开发者

JQuery Ajax and concatenated string

开发者 https://www.devze.com 2023-03-25 01:47 出处:网络
I`m trying to do an Ajax Request but for some reason it wont accept my concatenated string. When the query should have some parameters it leaves them out and makes GET call.

I`m trying to do an Ajax Request but for some reason it wont accept my concatenated string. When the query should have some parameters it leaves them out and makes GET call.

Here is a tiny piece of the code that I`ve written.

        var queryString = "";
        var separator = "?";

        for (param in config.query) {
            queryString = queryString.concat(separator, param, "=", config.query[param]);
            separator = "&";
        }

        var url = config.url + queryString;

    开发者_JAVA技巧    $.ajax({
            url : url,


The only reason I can think is that your QueryString is not properly encoded.
Try this

queryString = queryString.concat(separator, param, "=", encodeURIComponent(config.query[param]));


Try to see if the content inside url after this line var url = config.url + queryString; add alert(url); see if the content is what you need it to be


You might use data parameter to pass your params:

var queryString = "";
var separator = "";

for (param in config.query) {
    queryString = queryString.concat(separator, param, "=", config.query[param]);
    separator = "&";
}

$.ajax({
    url: config.url,
    data: queryString,
    ...
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号