I have an input field which accepts college name, and some other input fields for other usage.
1) Next, I'm creating a JSON structure with all these inputs and
2) Doing JSON.Stringify(JSONdata) for this JSON data.
3) Setting the XHR content-type header to:
xhr.setRequestHeader("Content-Type", "application/X-www-form-urlencoded");
calling a post request to server with this stringified input.
There everything works fine, except for this one particular college input which looks something like this:
St. Joseph's College of Arts & Science, Cityname.
After parsing the data at server side, I'm expecting my string at server to look something like this:
"college":"St. Joseph\'s College of Arts & Science, Cityname",
Instead it looks like:
"college":"St. Joseph\'s College of Arts ',' Science, Bangalore",
The & is getting replaced by a , and thus throwing an error:
: Unexpected end of JSON input<br>    at Object.parse (native)<br>    at server.js:206:28<br>    at Layer.handle [as handle_request] 
I want it to accept all the input field no matter what's inside it.
 
     
     
    