我使用这个简单的代码,但它不能正常工作(在我看来):
$(document).on("click", "#summary_and_tables #tables ul li a", function() {
var url = "index.php/table/show/"+this.hash;
console.log(url);
$.ajax({
type: "POST",
url: url,
dataType: 'json',
success: function(response) {
if(response.status == 'ok') {}
}
});
});
控制台的输出是:
index.php/table/show/#summary
但是ajax请求发送到:
http://test.loc/st_base/index.php/table/show/
最佳答案
不幸/幸运的是,没有什么问题。事情按预期进行。浏览器只是不向服务器发送哈希值。 如果确实需要传递,则放入data中:
var url = "index.php/table/show/";
var hashOnly = this.hash;
$.ajax({
type: "POST",
data: {myhash: hashOnly},
url: url,
dataType: 'json',
success: function(response)
{
if(response.status == 'ok')
{
}
}
});
关于javascript - jQuery ajax,url 属性无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17380839/