Search for a thread entitled "Automatic JSON response evaluation in
prototype 1.5.1" and you should probably find what you need.
Unfortunately, that thread was never specifically resolved because the
original poster seemed to have some form of problem in his JSON but
either way it does explain the automatic JSON evaluation in prototype.
- Dash -
Mark Holton wrote:
> ...whoops, forgot to pass my parameters into the Ajax.Request. So now the
> Ajax.Request is successfully completing (knew that was something small)
>
> ...but I still get a return (in the alert: alert(json ? Object.inspect(json)
> : "no JSON object");) of
> "no JSON object"
>
> ... hmmm.....
>
>
>
> On 6/4/07, Mark Holton <[EMAIL PROTECTED]> wrote:
>
>> Do I need something like this:
>> eval('(' + this.header( 'X-JSON') + ')')
>>
>> (taken from Cody Swann,
>> http://ajaxian.com/archives/prototype-extension-dynamic-script-pattern-support
>> ).
>> I'm guessing my problem is simpler, and I'm leaving something small out
>> related to the header though.
>> Thanks for any help
>> -Mark
>>
>>
>> 1. evalJSON: function() {
>> 2. if (this.transport.json ){ return this. transport.json; }
>> 3. else
>> 4. {
>> 5. try {
>> 6. return eval('(' + this. header('X-JSON') + ')');
>> 7. } catch (e) { }
>> 8. }
>> 9. }
>>
>>
>>
>> On 6/4/07, Mark Holton <[EMAIL PROTECTED]> wrote:
>>
>>> Hey guys,
>>>
>>> I'm probably missing something simple. (using Prototype 1.5.0., works
>>> great).
>>>
>>> I'm requesting some data on the back-end, and return a JSON string. The
>>> JSON string returned is exactly, for example:
>>> {"FName":"Mark","LName":"Holton","EmailAddress":" [EMAIL PROTECTED]
>>> ","Phone":4255555555}
>>>
>>> I can return that JSON string and stuff it into any dom element with
>>> Ajax.Updater without a problem. But I'd like to pass the data into the
>>> function using Ajax.Request, then populate elements on the page, such as
>>> $('txFirstName').value = jsonobj.FName; $('txLastName').value =
>>> jsonobj.LName; etc.
>>>
>>> There must be something wrong with how I'm trying to do this, however,
>>> as I'm getting no response when using Ajax.Request, whereas I am able to
>>> display the json in a DOM element when using Ajax.Updater. I'm
>>> wondering if it's because Updater sees the text string okay, yet, in order
>>> for JS to parse the incoming JS I have to do so with a header?:
>>>
>>> <!-- this isn't working for me -->
>>> function PopulateViaSID(SID) {
>>> var passSID = encodeURIComponent(parseInt(SID));
>>>
>>> var pars = 'FORM.passSID =' + passSID ;
>>>
>>> new Ajax.Request()
>>> var url =
>>> '/SShow/Model/AjaxCalls/sshow_caller_populateRef.cfm';
>>> new Ajax.Request(url, {
>>> method: 'get',
>>> onSuccess: function(transport, json) {
>>> alert(json ? Object.inspect(json) : "no JSON
>>> object");
>>> }
>>> });
>>>
>>> <!-- this does return the string from the server and populate a DOM
>>> element -->
>>> new Ajax.Updater(resultDomElem,
>>> '/SShow/Model/AjaxCalls/sshow_caller_populateRef.cfm',
>>> {
>>> asynchronous:true,
>>> parameters: pars,
>>> onSuccess:function(){
>>> $('txtRefNotes').value = 'hello'; //this worked
>>> // $('txtRefFirstName').value = oUser.FName; //was
>>> hoping I could do this, but it didn't work
>>> Element.setOpacity(resultDomElem, 0.0);
>>> Effect.Appear(resultDomElem, { duration: 0.5 });
>>> new Effect.Highlight(resultDomElem,
>>> {startcolor:CEB195, endcolor:F8F8D2});
>>> }
>>> }
>>> );
>>>
>>>
>>
>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---