Click here to Skip to main content
15,896,512 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i don't know how to use single quotes and double quotes in ajax please correct the below data

What I have tried:

data: "{'Id':'"+ Id +"','FName': '" + FName + "', 'FStatus': '"+ FStatus + "', 'UDate': '" + UDate + "' }"
Posted
Updated 27-Dec-16 21:00pm
v2

Do not do this. Concatenation is not only hard to read and also very confusing. Actually, you can create a JavaScript object[^] that takes the parameters as properties, then use JSON.stringify()[^] to turn it into a JSON string. See example:
JavaScript
fname="peter";
lname="leow";

var obj = {};
obj.fname = fname;
obj.lname = lname;

var myJSON = JSON.stringify(obj);
document.getElementById("demo").innerHTML = myJSON;

The output is
{"fname":"peter","lname":"leow"}

Check out JSFiddle[^]
 
Share this answer
 
v2
Comments
Afzaal Ahmad Zeeshan 28-Dec-16 2:59am    
5ed.
Peter Leow 28-Dec-16 3:10am    
Thank you, Afzaal.
It is obvious, that you in a terrible rush to became a programmer, that you have no time to clarify names and distinguish subjects...
You ask about AJAX, label your question as jQuery and gave an example of JSON...However, all you need is to understand is single- and double-quotes in JavaScript and/or escaping strings in JavaScript...
It is also would help to actually read about JSON[^], and how to use to wrap data and pass between applications...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900