0

How I can make this:

$.ajax({
    type: "POST",
    url: "",
    data: dataString,
    cache: false,
    success: function(html){}
});

but datatype json

and using it by php

please tell me an example because i tired to search in the internet

2
  • Could you please explain your question a little better? Commented Feb 19, 2010 at 11:17
  • Are you trying to post JSON data to the server or retrieve JSON data from the server? Commented Feb 19, 2010 at 11:19

1 Answer 1

1

Use the dataType property to have a JSON response parsed into a native object:

$.ajax({ 
    type: "POST", 
    url: "", 
    data: dataString,
    dataType: "json",
    cache: false, 
    success: function(html){} 
});

If you're trying to post JSON data to the server, you will need json2.js to convert your object into a JSON string before posting it:

data: { json: JSON.stringify(someObj); }

and in php >=5.2:

$data = json_decode($_POST['json']);
Sign up to request clarification or add additional context in comments.

2 Comments

this great but know what is the form of php page
@moustafa: I'm not sure I understand what you're asking. Are you asking for the php code to parse the JSON data? If so, see the bottom of my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.