Click here to Skip to main content
13,193,441 members (39,214 online)
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
v2
Rate this: bad
 
good
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:
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[^]
  Permalink  
v2
Comments
Afzaal Ahmad Zeeshan 28-Dec-16 2:59am
   
5ed.
Peter Leow 28-Dec-16 3:10am
   
Thank you, Afzaal.
Rate this: bad
 
good
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...
  Permalink  

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 |
Web02 | 2.8.171018.2 | Last Updated 28 Dec 2016
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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