I created a WCF Service hosted in JQuery, when I navigate to the web service in browser and pass a parameter to it, I get back the data correctly, for example like this:
htp://server:6666/sites/test/_layouts/15/mycustomservice.svc/getitembyid(1)
I get back the item correctly, but when I do that in a webpart, I keep getting errors, he is the ascx for the webpart:
<input id="txtID" type="text" name="txtID" />
<input id="btnID" type="button" value="Get Item Name By ID" onclick="GetMyItem()" />
<script type='text/javascript'>
var txtValue = document.getElementById("txtID").value;
function GetMyItem() {
$.ajax({
type: 'POST',
contentType: 'application/json',
dataType: 'json',
url: 'htp://server:6666/sites/test/_layouts/15/mycustomservice.svc/getitembyid',
data: '{"ID":"1"}',
success: function (itemtitle) {
alert(itemtitle);
},
error: function () {
alert('There was an error');
return;
}
});
}
</script>
I keep getting: There was an error, any solution?