jQuery send string as POST parameters

Mirgorod picture Mirgorod · Feb 18, 2011 · Viewed 435.1k times · Source

I want to send a string as an ajax Post parameter.

The following code:

$.ajax({
   type: "POST",
   url: "http://nakolesah.ru/",
   data: 'foo=bar&ca$libri=no$libri',
   success: function(msg){
     alert('wow'+msg);
   }
});

Is not working. Why?

Answer

Darin Dimitrov picture Darin Dimitrov · Feb 18, 2011

Try like this:

$.ajax({
    type: 'POST',
    // make sure you respect the same origin policy with this url:
    // http://en.wikipedia.org/wiki/Same_origin_policy
    url: 'http://nakolesah.ru/',
    data: { 
        'foo': 'bar', 
        'ca$libri': 'no$libri' // <-- the $ sign in the parameter name seems unusual, I would avoid it
    },
    success: function(msg){
        alert('wow' + msg);
    }
});