0

I know i am proberly being dumb or something but for the life in me i cannot get this function to work in IE7+, works in every other non IE browser:

/inbox/get_auth_replies (JSON Returned):

{"default_message":"Thank you, we have already recieved your request. A member of the team will contact you shortly.","repeated_message":"Thank you for contacting us. A member of the team will contact you shortly."}

jQuery:

var $keyword_id = 123;
$.post('/inbox/get_auto_replies', {keyword_id: $keyword_id}, function(resp) {
    console.log(resp.default_message);  
    $('#inbox_default_message').val(resp.default_message);
    $('#inbox_repeat_message').val(resp.repeated_message);
}, 'json');

in IE reports:

SCRIPT5007: Unable to get value of the property 'default_message': object is null or undefined.

I can see it is returning the data but just cannot see/parse it?

I have looked at everything on SO and nothing seems to help.

Any help would be appreciated.

Thanks.

7
  • can you console.log(resp)? is it valid json? what content type is your script responding with? Commented Jun 7, 2012 at 13:34
  • 1
    ummm. I think IE won't recognize console.log(), or would it? Commented Jun 7, 2012 at 13:41
  • Is the code inside a jQuery ready function? In IE it can sometimes throw this error when it's trying to execute before the DOM is fully loaded... But @UmairP comment is probably the reason - though console does work for IE8+ I believe, not 7 though Commented Jun 7, 2012 at 13:43
  • @dm03514 - I have edited my code, UmairP - it does support it. Commented Jun 7, 2012 at 13:51
  • @danrichardson sorry i didnt see your comment, yes its inside an onclick element. Commented Jun 7, 2012 at 14:09

2 Answers 2

1
  1. Change $.post to $.ajax and make use of the error callback and log the error.

  2. I would suggest changing var $keyword_id = 123; to var keyword_id = 123; Use $ before a variable name when indicating that its a jquery dom element

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

Comments

0

Have you tried using jQuery.getJSON instead? Same structure as the .post (minus the 'json' parameter).
Could then loop through the items to try and work it out and alert/console.log them?
http://api.jquery.com/jQuery.getJSON/

It might be a case of not being able to parse the JSON in IE7, does it work in IE9 (if you can try it). I know you mentioned IE7+, but which have you tried? I think there is native JSON parsing in IE8 onwards.

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.