我使用JQuery对ASP.NET页面方法进行Ajax回调。一切正常。但是,当我单击超链接进入一个新页面时,目标页面却不会正常响应。它似乎在等待回调结束,因为目标页面响应的时间与完成回调所需的时间相同。如果没有正在进行的回调,新页面将立即响应。通过调试器中的代码,我看到当单击超链接时会调用错误处理程序,超链接会中止回调,并将readyState设置为4,状态设置为0。
那么,如果单击超链接时长时间运行的回调被正确中止,为什么要花这么长时间才能到达新页面?
谢谢!
An error in the auto generated JavaScript. Can you enable script debugging and see if the error occurs before you leave the page?
Have you ever successfully executed your Ajax on your particular system? If you haven't, it's probably a browser compatibility issue - I would try JQuery, Dojo, or Scriptaculous because they work smoothly with common browsers. Raw ajax can be quite frustrating and difficult to debug.
And like Yuriy said, some code would help. Good luck!
Firebug for Firefox was born to figure out this type of problem.
Enable Firebug, keep the console tab open. A new line will appear for each web service call in the console. Cool think is you can inspect what is being sent and received.
The 'success' parameter (along with 'error', 'dataFilter', etc...) of the $.ajax function is actually a callback function that is executed when you receive the response from the server.
So the script will continue running after you make your AJAX request and then return to that callback function when you receive the response.
Example
$.ajax({
url: 'ajax/test.html',
success: function(data) {
//Runs after response is received
//Put stuff that depends on the response from the server here
}
});
//Next statement runs immediately after request
//Put stuff here that can run right away