0

我使用这个简单的代码,但它不能正常工作(在我看来):

$(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/
4

2 回答 2

2

Unfortunately/luckily, nothing is wrong. Things work as expected. Browsers just do not send hash to the server. If you really need to pass it, put it into 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')
        {
        }
    }
});
于 2013-06-29T13:51:24.037 回答
0

You are using relative url, this will append index.php/table/show/"+this.hash to current location of your script.

It appears that your script is located at "http://test.loc/st_base/"

Try specifying full url, starting with "http://mycorrectsite.com/blah/index.php/table/show..."

于 2013-06-29T13:51:11.980 回答