JQuery Ajax and concatenated string
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,
...
});
精彩评论