[Proto-Scripty] Re: using onSuccess(transport, json) and header(Content-type: application/x-json)
Try this: //php $myArray=array('status'=1); $jsonData=json_encode($myArray); return $jsonData; Dont forget the header. //javascript/prototype jsonResponse=eval('('+response.responseText+')'); Access data as array: var myVal=jsonResponse[0].status; Hope that helps On 10/7/08, liketofindoutwhy [EMAIL PROTECTED] wrote: For some reason, no matter what I use new Ajax.Request(url, { method: 'get', onSuccess: function(transport, json){ //alert(Object.inspect(json)); alert(json ? Object.inspect(json) : no JSON object); }, ... }); and then in PHP, when i use header('Content-type: application/x-json'); echo '{ status : 1 }'; the ajax will come back showing no JSON object it doesn't matter if i use text/x-json or text/json or application/ json and it is prototype 1.6.0.3... is there something wrong the header or the formatting of the content? thanks. -- Sent from Gmail for mobile | mobile.google.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: using onSuccess(transport, json) and header(Content-type: application/x-json)
Something I forgot json in your case will recieve the header while transport the XHR object. So will have to evaluate transport not json On 10/7/08, liketofindoutwhy [EMAIL PROTECTED] wrote: For some reason, no matter what I use new Ajax.Request(url, { method: 'get', onSuccess: function(transport, json){ //alert(Object.inspect(json)); alert(json ? Object.inspect(json) : no JSON object); }, ... }); and then in PHP, when i use header('Content-type: application/x-json'); echo '{ status : 1 }'; the ajax will come back showing no JSON object it doesn't matter if i use text/x-json or text/json or application/ json and it is prototype 1.6.0.3... is there something wrong the header or the formatting of the content? thanks. -- Sent from Gmail for mobile | mobile.google.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: using onSuccess(transport, json) and header(Content-type: application/x-json)
Hi, You're looking for the JSON in the second parameter to onSuccess, but that's the result of evaling the X-JSON *header*. From http://www.prototypejs.org/api/ajax/options: ...all callbacks (except onException) are invoked with two parameters: the XMLHttpRequest object and the result of evaluating the X-JSON response header, if any (can be null). You're sending JSON back as the body of the response, not in an X-JSON header. If you do that, use transport.responseJSON in your onSuccess handler: onSuccess: function(transport){ alert(transport.responseJSON ? Object.inspect(transport.responseJSON) : no JSON object); }, Or if you really want to send an X-JSON header (where the body of the response is something else), you'll have to modify your PHP to do that. HTH, -- T.J. Crowder tj / crowder software / com On Oct 7, 2:54 am, liketofindoutwhy [EMAIL PROTECTED] wrote: For some reason, no matter what I use new Ajax.Request(url, { method: 'get', onSuccess: function(transport, json){ //alert(Object.inspect(json)); alert(json ? Object.inspect(json) : no JSON object); }, ... }); and then in PHP, when i use header('Content-type: application/x-json'); echo '{ status : 1 }'; the ajax will come back showing no JSON object it doesn't matter if i use text/x-json or text/json or application/ json and it is prototype 1.6.0.3... is there something wrong the header or the formatting of the content? thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---