Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax POST method converts my "+" value in a string to " " why?

I cant figure out why in ajax post "+" sign converts to " ".please explain ?

like image 497
Kumar Avatar asked Jan 19 '10 13:01

Kumar


People also ask

What does Ajax POST do?

jQuery Ajax Post method, or shorthand, $. post() method makes asynchronous requests to the web server using the HTTP POST method and loads data from the server as the response in the form of HTML, XML, JSON, etc.

How GET and POST method are used in Ajax?

GET is basically used for just getting (retrieving) some data from the server. Note: The GET method may return cached data. POST can also be used to get some data from the server. However, the POST method NEVER caches data, and is often used to send data along with the request.

What is data in Ajax POST?

data : A plain object or string that is sent to the server with the request. success : A callback function that is executed if the request succeeds.it takes as an argument the returned data. It is also passed the text status of the response. dataType : The type of data expected from the server.

Does Ajax use Get or POST?

Sending Data to the ServerBy default, Ajax requests are sent using the GET HTTP method. If the POST method is required, the method can be specified by setting a value for the type option. This option affects how the contents of the data option are sent to the server.


1 Answers

Use the encodeURIComponent() function to turn your data in valid encoded data for the request:

xhr.open("POST", url, true);
xhr.send(encodeURIComponent(postdata));
like image 95
Roland Bouman Avatar answered Sep 23 '22 02:09

Roland Bouman