我只是想做一个像这样的简单请求:
$('.asd').change(
function () {
$.ajax({
url: 'http://127.0.0.1/folder/index.php/controller/action/integer',
success: function(data){}
});
}
);
Run Code Online (Sandbox Code Playgroud)
这段代码试图转到http://127.0.0.1/folder/index.php/controller/[object%20Object]而获得404.它从哪里拉出对象?我正在使用一个简单的字符串.
sff*_*ffc 18
对我来说问题是我使用的是$.post代替$.ajax.
// fails:
$.post({
url: "/example/" + this.id,
// ...
});
// works:
$.ajax({
url: "/example/" + this.id,
// ...
});
Run Code Online (Sandbox Code Playgroud)
ajax期望参数图.
post期望单个参数:
// fails:
$.post({
url: "/example/" + this.id,
// ...
});
// works:
$.post("/example/" + this.id);
Run Code Online (Sandbox Code Playgroud)
小智 4
我遇到了同样的问题,并四处寻找答案。不幸的是,这位贡献者再也没有回来。我的错误是一个愚蠢的错误。从 Ajax 返回后,我无意中以保留字命名了我的变量。这是我所拥有的:
$.post('/MyApp.php', { param: 'getLocation' },
function(xml) {
location=$(xml).find('Location');
}
});
Run Code Online (Sandbox Code Playgroud)
像这样编码,从 Ajax 返回后,页面将重定向到 http://myurl/[Object%20object],这现在完全有意义了。
解决方案:将“location=$...”更改为“clocation=$...”希望这个答案对其他人有帮助。这是一个很难调试的问题。