Jquery Ajax using json is getting a undefined value

$.ajax({                
    type: "POST",
    url: "check.php",
    data: "checkit=" + $("#checkEmail").val(),
    success: function(response){
        $("#userCheck").html(response.status);
        if(response.status == true){
            alert("yay");
        }else{
            alert("dsfds");
        }
    }
}, 'json');

someone here suggested doing my ajax returns using json...

here is my php file returning the json..

$data = {success:true};
    echo json_encode($data);

im getting undefined for the return. Perhaps someone here could point me to my mistake?

Answers


You are also missing

dataType: 'json'

and your PHP is wrong:

$data=array('status'=>true);

UPDATE

Here are a few suggestions I would try:

1) 'dataType' (case-sensitive I believe)

2) try using the 'contentType' option as so:

contentType: "application/json; charset=utf-8"

I'm not sure how much that will help as it's used in the request to your post url, not in the response. See this article for more info: http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax (It's written for asp.net, but may be applicable)

3) Triple check the output of your post url and run the output through a JSON validator just to be absolutely sure it's valid and can be parsed into a JSON object. http://www.jsonlint.com

Hope some of this helps!


Need Your Help

How to perform “find” command with another embedded command in another directory?

batch-file window dos ms-dos

I would like to write a function which is to perform "find" command with another embedded command, %recent% in another directory(share drive).

Proper date time format in rails

ruby-on-rails

In my application I want to display the date in this format: 21st Aug,2012 07:30 PM. I have done it using strftime like this:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.