我的 jquery.post 调用出现问题。
当我执行以下脚本时:
<script type="text/javascript">
$(document).ready(function(){
//var cmsr_url = 'http://127.0.0.1/sphere/modules/cmsrating/ajax.php?rand=1231';
var cmsr_url = 'ajax/test.html';
$('.star, .auto-submit-star').rating({
callback: function(value, link){
alert(cmsr_url);
$.post({
url: cmsr_url,
// also tried to put here a string like below
// url: 'http://127.0.0.1/sphere/modules/cmsrating/ajax.php?rand=1231'
data: {rating : value},
success: function(){
alert('done!');
},
dataType: 'json'
});
}
});
});
</script>
我的警报显示正确的网址。但是我的 Firebug 显示请求的网址是:
http://127.0.0.1/sphere/pl/content/%5Bobject%20Object%5D
它从哪里来?
最佳答案
我认为问题在于您尝试使用 $.post 函数,就像使用 $.ajax 函数一样。从文档看来,post 不接受像 $.ajax 那样的选项。 https://api.jquery.com/jQuery.post/
试试这个:
$.ajax({
url: cmsr_url,
// also tried to put here a string like below
// url: 'http://127.0.0.1/sphere/modules/cmsrating/ajax.php?rand=1231'
data: {rating : value},
success: function(){
alert('done!');
},
dataType: 'json',
type: 'POST'
});
关于javascript - jQuery.post 使用当前位置的修改后的 url,而不是提供的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23226701/