Click here to Skip to main content
13,665,737 members
Rate this:
Please Sign up or sign in to 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 27-Dec-16 20:34pm
Updated 27-Dec-16 21:00pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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:

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

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

The output is

Check out JSFiddle[^]
Afzaal Ahmad Zeeshan 28-Dec-16 2:59am
Peter Leow 28-Dec-16 3:10am
Thank you, Afzaal.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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...

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web05-2016 | 2.8.180810.1 | Last Updated 28 Dec 2016
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100