1

I have a problem with processing a JSON object.

When I do echo the result I get this:

result : undefined

Image of undefined result

$.post("./php/date_information.php", function(temp){
        alert(temp.weekNumber); // HERE
        $('select[name="week"]').val(temp.weekNumber);
      });

but when I change my code I get this

result : {"year":"2018","weekNumber":"39","status":"200"}

Image of correct

$.post("./php/date_information.php", function(temp){
        alert(temp); // Here
        $('select[name="week"]').val(temp.weekNumber);
      });

PHP script return (JSON FORMAT):

{"year":"2018","weekNumber":"39","status":"200"}

I have no idea why JQuery doesn't take temp.weekNumber. Any ideas?

1 Answer 1

1

Set the content type to json in your PHP script, before echoing the content

header('Content-Type: application/json');
Sign up to request clarification or add additional context in comments.

Comments

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.