简体   繁体   中英

How do I send brackets “%5B” “%5D” as params on an Ajax Request using GET as method?

Using Ajax and the method GET, I am trying to send an url with brackets, but I am not getting the right encoding of them:

Request URL:http://myurl/search.html?_dc=1382510050331&search%5Bpostcode%5D=96231

instead of:

Request URL:http://myurl/search.html?_dc=1382510050331&search[postcode]=96231

Error:

Status Code:502 Host not found

Here is a snippet of my code:

Ext.Ajax.request({
    url: 'http://myulr.lan/fpsearchjson.html',
    method: 'GET',
    params: {
        "geosearch[postcode]":91111
    },
    success: function(response){
        console.log("success");
    },
    failure: function(response){
        console.log("failure");
    }
});

Any help will be appreciated!

%5B and %5D are the url-encoded values of [ and ] . This should be encoded like it is in your example.

The problem seems to be that you are unable to reach the server. Try to reach the server in any way. Maybe open the URL in your favorite browser or telnet to it: telnet my.server.com 80

您需要转换您的Get请求,尽管ajax应该首先转换为ASCII,我也遇到了同样的问题,尽管我将GET请求转换为ASCII,然后再次解码以供使用:

You can use escape function to encode ,decode your url and parameter. On other side you can easily get that value in original format
for example

escape("It's me!") // result: It%27s%20me%21

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM