I am new to web service. In my project, I connected Web Service(everything is ready-made) now when I tried to run I got the below error.
ERROR -->
Uncaught SyntaxError: Unexpected token <
The Web service and my page are in same solution but different projects.
The related code is as follows:
jQuery (URL: 11761)
function GetAllCategories() {
$.ajax({
url: "http://localhost:12015/myWebService.asmx?op=GetCategories",
type: "POST",
dataType: "jsonp",
data: "{}",
contentType: "application/jsonp; charset=utf-8",
success: function (data) {
var categories = data.d;
$.each(categories, function (index, category) {
alert(category.CategoryId);
});
},
error: function (e) {
alert(e.message);
}
});
}
Web Service (URL: 12015)
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<Categories> GetCategories()
{
//Code
}
Before asking here I have gone through this link(cant understand it)
EDIT:
Got alternative answer from this post.
<</script>tag at the end.POSTandjsonpwhich are not compatible without some hacking - see stackoverflow.com/questions/2699277/post-data-to-jsonpasp.netbut stackoverflow.com/questions/2380551/… may help. The problem seems to be that you are usingjsonpwhich adds?callback=?to the end of the URL. The handler (your Web Service) for the URL must also be coded to return a padded response i.e. a response wrapped in a JavaScript function call. I suspect you just want to be doing a simple ajaxGETto that URL that just returns a simple JSON response.url: "http://localhost:12015/myWebService.asmx/GetCategories"and ERROR,unexpected token <If I useurl: "http://localhost:12015/myWebService.asmx?op=GetCategories"