So'k i sorted it .....

On the PHP end i do this ...

 header('Content-Type: application/json');// text/html



and on

the onSuccess i do this ...


onSuccess : function(d) {

       var header=d.getHeader('Content-Type')
        if(header=='application/json') {
         var data=d.responseText.evalJSON();
        } else  { ......

This has saved me hours of work !!!!

Regards
Alex

----- Original Message ----- 
From: "Richard Quadling" <rquadl...@googlemail.com>
To: <prototype-scriptaculous@googlegroups.com>
Sent: Wednesday, June 10, 2009 11:02 AM
Subject: [Proto-Scripty] Re: Bizzarre goings on


>
> 2009/6/10 Alex McAuley <webmas...@thecarmarketplace.com>:
>>
>> Richard.
>>
>> On a slight side note is it possible to evaluate the response from the
>> request to see if it is Json or HTML ...
>>
>> In the backend i can output whatever header i like and i would like to on
>> the request evaluate if it is JSON (and if so do something) or if its
>> text/html/javascript do somehting else ....
>>
>> Is this possible with prototypejs
>>
>> Regards
>> Alex
>>
>> ----- Original Message -----
>> From: "Richard Quadling" <rquadl...@googlemail.com>
>> To: <prototype-scriptaculous@googlegroups.com>
>> Sent: Wednesday, June 10, 2009 10:31 AM
>> Subject: [Proto-Scripty] Re: Bizzarre goings on
>>
>>
>>>
>>> 2009/6/10 Alex McAuley <webmas...@thecarmarketplace.com>:
>>>>
>>>> As i said it was working and nothing changed except one line an - >
>>>> if($('overlay')) {...}
>>>>
>>>> whihc i have now removed ...... its very weird, i will strip it down to
>>>> bear
>>>> minimum and build it up agian........
>>>>
>>>> I really hate debugging Internet explorer as using debug bar - the line
>>>> numbers and charachters do not match what is going on!!
>>>>
>>>> ----- Original Message -----
>>>> From: "Richard Quadling" <rquadl...@googlemail.com>
>>>> To: <prototype-scriptaculous@googlegroups.com>
>>>> Sent: Wednesday, June 10, 2009 10:17 AM
>>>> Subject: [Proto-Scripty] Re: Bizzarre goings on
>>>>
>>>>
>>>>
>>>> 2009/6/10 Alex McAuley <webmas...@thecarmarketplace.com>:
>>>>>
>>>>> The JSON returned is ok - this was the first thng i checked....
>>>>>
>>>>> Here is the returned JSON..
>>>>>
>>>>> {"Error":"No","ErrorMessage":"None","Refresh":"1"}
>>>>>
>>>>> As you can see from that and the code i pastebinned there is no 
>>>>> trailing
>>>>> comma anywhere.. and it -was- working perfectly fine then just stopped
>>>>> !!
>>>>>
>>>>> This is really confusing, i will continue to investigate !
>>>>>
>>>>> Thanks
>>>>> Alex
>>>>>
>>>>> ----- Original Message -----
>>>>> From: "david" <david.brill...@gmail.com>
>>>>> To: "Prototype & script.aculo.us"
>>>>> <prototype-scriptaculous@googlegroups.com>
>>>>> Sent: Tuesday, June 09, 2009 10:09 PM
>>>>> Subject: [Proto-Scripty] Re: Bizzarre goings on
>>>>>
>>>>>
>>>>>>
>>>>>> Hi Alex,
>>>>>>
>>>>>> If the code WAS working, the error could be on the received JSON ?
>>>>>> One though, IE don't like misplaced comma on JSON. For exemple, last
>>>>>> element of an array that is followed by a comma don't work on IE.
>>>>>>
>>>>>> --
>>>>>> david
>>>>>>
>>>>>>
>>>>>> On 9 juin, 16:31, Jeztah <webmas...@thecarmarketplace.com> wrote:
>>>>>>> AFternoon guys/gals
>>>>>>>
>>>>>>> http://pastie.org/505747
>>>>>>>
>>>>>>> Some weird behaviour in internet explorer .....
>>>>>>>
>>>>>>> The code in the link above works in all browsers except Internet
>>>>>>> explorer ..... It was working untill earlier today and i am now not
>>>>>>> sure why... i have reverted any changes back to what they were when 
>>>>>>> it
>>>>>>> was working ....
>>>>>>>
>>>>>>> At a glance can anyone see an error that would halt Internet
>>>>>>> Explorer....
>>>>>>>
>>>>>>> The strange thing is .. IE doesnt even throw an error, it does the
>>>>>>> requests fine just doesnt do the bits after - its like it isnt 
>>>>>>> reading
>>>>>>> the JSON response....
>>>>>>>
>>>>>>> As i said its working in all other browsers fine and has been for a
>>>>>>> while so i know its not the backend response as it used to work in
>>>>>>> IE!!..
>>>>>>>
>>>>>>> Thanks in advance
>>>>>>>
>>>>>>> Alex
>>>>>> >
>>>>>>
>>>>>
>>>>>
>>>>> >
>>>>>
>>>>
>>>> What is the header you are using in the JSON response?
>>>>
>>>> Normally, if you use an appropriate header, you don't need to
>>>> evalJSON() as this is done for you and presented as the second
>>>> parameter to the onSuccess() callback.
>>>>
>>>>
>>>>
>>>> --
>>>> -----
>>>> Richard Quadling
>>>> Zend Certified Engineer :
>>>> http://zend.com/zce.php?c=ZEND002498&r=213474731
>>>> "Standing on the shoulders of some very clever giants!"
>>>>
>>>>
>>>>
>>>>
>>>> >
>>>>
>>>
>>> You could use FireBugLite [1]. Offers a lot of the facilities found in
>>> its big brother in FireFox.
>>>
>>> You can then use console.info() calls in your code to help report what
>>> is going on.
>>>
>>> Regards,
>>>
>>> Richard.
>>>
>>> [1] http://getfirebug.com/lite.html
>>> --
>>> -----
>>> Richard Quadling
>>> Zend Certified Engineer : 
>>> http://zend.com/zce.php?c=ZEND002498&r=213474731
>>> "Standing on the shoulders of some very clever giants!"
>>>
>>> >
>>>
>>
>>
>> >
>>
>
> Use the appropriate headers on the server.
>
> If you send (PHP) ...
>
> header("{$_SERVER['SERVER_PROTOCOL']} 200 OK", True, 200);
> header('Content-type: X-JSON');
> echo json_encode($m_Response);
>
> or
>
> header("{$_SERVER['SERVER_PROTOCOL']} 200 OK", True, 200);
> header('Content-type: application/javascript');
> echo "{$_POST['JSONP']}(" . json_encode($m_Response) . '); //';
>
> for JSON/JSONP, then prototype will handle it correctly.
>
> But if you are NOT sending JSON encoded data, but straight HTML, then
> you use the text/html content type.
>
> So. When this gets to prototype, the second param will be populated
> for the JSON data (up to you to process the object).
> The JS will be executed for JSONP (you don't need to do anything else).
> The HTML will be sent to the appropriate container (if you are using
> an updater request).
>
> No need to "determine" anything. Just use the right headers.
>
> Well, you could test to see if the second param to the onSuccess is
> present. If so, then it is JSON, if not then it is not.
> -- 
> -----
> Richard Quadling
> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
> "Standing on the shoulders of some very clever giants!"
>
> >
> 


--~--~---------~--~----~------------~-------~--~----~
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 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to