0
$.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?

2 Answers 2

5

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!

Sign up to request clarification or add additional context in comments.

1 Comment

for some reason adding dataType: "json", makes nothing happen.. none of my alerts will even work
1

You're referencing a different variable, you're sending success (invalidly at that) but checking status. With your current jQuery, it should be:

echo json_encode(array('status' => true));

1 Comment

$("#userCheck").html(response.status); is it the html part of this? it seems like it returns everything as html

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.