Reputation: 87
Below is the code I am working on, my goal is to convert string to an actual object and just simply display the data from ajax call. But it seems that the string value cant work this way.
var string = "first: 'George', last: 'Smith'";
$.ajax({
type: 'POST',
url: 'ajax.php',
data: {string}
}).done(data){
alert(data);
}
Upvotes: 0
Views: 60
Reputation: 14943
What you are looking for is:
There are plenty of examples on the web.
Upvotes: 0
Reputation: 4753
Can you try this:
var Params= {first: 'George', last: 'Smith'};
$.ajax({
type: "Post",
dataType: 'json',
url: 'ajax.php',
data: JSON.stringify(Params),
contentType: 'application/json',}).done(data){
alert(data);
}
Upvotes: 0