jQuery: Use of undefined constant data assumed 'data'

Posted by morpheous on Stack Overflow See other posts from Stack Overflow or by morpheous
Published on 2010-04-23T15:18:14Z Indexed on 2010/04/23 15:33 UTC
Read the original article Hit count: 260

Filed under:
|

I am trying to use jQuery to make a synchronous AJAX post to a server, and get a JSON response back.

I want to set a javascript variable msg upon successful return

This is what my code looks like:

$(document).ready(function(){
    $('#test').click(function(){
    alert('called!');
    jQuery.ajax({
      async: false,
      type: 'POST',
      url: 'http://www.example.com',
      data: 'id1=1&id2=2,&id3=3',
      dataType: 'json',
      success: function(data){ msg = data.msg; },
      error: function(xrq, status, et){alert('foobar\'d!');}
     });
});

[Edit]

I was accidentally mixing PHP and Javascript in my previous xode (now corrected). However, I now get this even more cryptic error message:

uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIXMLHttpRequest.open]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js :: anonymous :: line 19" data: no]

What the ... ?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about php