Error $ .ajax () in jquery-1.6.2, but not in jquery-1.4.1

I used $.ajax() to use the local .asmx web service. Here is my code to call:

  $("#btnGetOne").click(function() { $.ajax({ type: 'POST', contentType: 'application/json; charset=utf-8', url: 'http://localhost:53003/TestWebService.asmx/GetServant', data: '{ "servant_id": "' + $("#txtServantID").val() + '" }', dataType: 'json', success: function(data, textStatus, jqXHR) { var jsnData = $.parseJSON(data.d); $('#DisplayArea').html(jsnData.Servant_Name); }, error: function(jqXHR, textStatus, errorThrown) { alert(textStatus + ' ' + errorThrown); } }); }); 

As you can see, the ajax call is executed when I press btnGetOne.

As in my question title, this works in jquery-1.4.1, but when I used jquery-1.6.2, I get errorThrown No Transport message.

Is there anything else I'm missing?

+6
source share
1 answer

Your HTML + JS page is probably not loaded from localhost:53003 when you try to use the Ajax URL located at localhost:53003 .

So it looks like you are trying to make a cross-domain request that is denied - see Same origin policy .


Taking a look at the jQuery.support documentation, you can enable jQuery.support.cors (quoting):

cors is true if the browser can create an XMLHttpRequest object, and if this XMLHttpRequest object has a property withCredentials .

To allow cross-domain requests in environments that do not yet support cors , but allow XHR cross-domain requests (windows gadget, etc.), set $.support.cors = true; .


And here are some links that might help:

+7
source

Source: https://habr.com/ru/post/893583/


All Articles