jQuery.getJSON read data -
why code below not working? can see in firebug data
variable contains reply data expect:
"[{"nextid":"stk000022"}]"
but when try , access value "undefined".
jquery.post( get_data_url, formdata, function(data) { sessionstorage.ticket_id = data[0].nextid; <--- undefined here }) .done(function(data) { showpopupmsg(successclass, false, "new ticket created!<br/>new ticket number: <strong>" + sessionstorage.ticket_id); // reset form jquery( '#partnernewticketform' ).reset(); }) .fail(function(jqxhr, textstatus, error ) { var syserror = textstatus + ", " + error; showpopupmsg(errorclass, logoutflag, "the application has failed create new ticket. error: " + syserror); }) .always(function(data) { });
since server returning json, need tell jquery it, giving 4th argument $.post
:
jquery.post( get_data_url, formdata, function(data) { sessionstorage.ticket_id = data[0].nextid; }, 'json')
specifying json
datatype
argument tells jquery should parse json object.
Comments
Post a Comment