开发者

jQuery.ajax() uses current page URL instead of specified URL

开发者 https://www.devze.com 2023-03-16 18:38 出处:网络
If I make this call on a page such as index.php: 开发者_开发问答jQuery.ajax(\"keepalive.php\");

If I make this call on a page such as index.php:

开发者_开发问答
jQuery.ajax("keepalive.php");

jQuery makes a request for index.php instead of keepalive.php.

This request is only to keep a session going, so I don't care about the result. According to the docs, simply specifying a URL is all that is needed. Any thoughts on why this doesn't work correctly?


Your code will work only if you're using jquery >= 1.5. For maximum compatibility, use the following:

jQuery.ajax({
    url: 'keepalive.php'
});

This code will run in any jquery version. Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号