Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery ajax whitespace and ampersand issue

I am doing something like this

var apiOptions = {
    url: url,
    dataType: 'jsonp',
    type: "GET",
    success: success
};

if(dataOptions) {
    apiOptions.data = {
        key: self.settings.key,
        limit: self.limit,
        address: dataOptions.address,
    };
}
$.ajax(apiOptions);

And it works fine for everything except for when I have " & ", so spaces around an ampersand. So the request parameter looks like "D+&+D,+enterprisess" or D+%26+D%2C. This then returns a 404 on the server.

Any idea what to do here ?

like image 238
StevieB Avatar asked Oct 05 '15 08:10

StevieB


1 Answers

For pass parameters with space and speacial character in ajax, you have use escape and unescape function.

var test = 'Exemplae Actão ç @#$%$ ';
var testEscape = escape(test);
console.info(test , testEscape ,  unescape(testEscape ));

This solve you problem

like image 196
RBoschini Avatar answered Sep 24 '22 08:09

RBoschini