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":"holtonma-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
","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");
// no alert displays when I try this
}
});
<!-- 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
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Hey Mark, I always hated the guts out of this json parameter in the callbacks. As explained in the docs (*cough*), it''s currently based on the X-JSON header, not the response''s body. You would need to use transport.responseText.evalJSON(true) instead. -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Chris,
Thanks for confirming. I found this (below) on an older thread and am going
to try it in the a.m..... looks promising given what you have confirmed.
Many thanks, (btw, like your BETA book. Bought it a couple weeks ago, been
bogged down, but should get more into it in the next couple of weeks. Lots
of good things in there I plan to review more than once.)
thanks again and cheers,
Mark
"Yes. If your JSON is in the response body, you will have to evaluate it
yourself. It must be the framework you''re using which is creating the
X-JSON header, perhaps? For example:
new Ajax.Request("some_page.cfm", {
parameters: {id: 6},
onComplete: function(transport) {
var json = transport.responseText.evalJSON(true);
/* ... do something else ... */
}
});
You''re responseText should then be valid JSON. For more information,
see http://prototypejs.org/api/string/evaljson."
On 6/4/07, Christophe Porteneuve
<tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org>
wrote:>
>
> Hey Mark,
>
> I always hated the guts out of this json parameter in the callbacks. As
> explained in the docs (*cough*), it''s currently based on the
X-JSON
> header, not the response''s body.
>
> You would need to use transport.responseText.evalJSON(true) instead.
>
> --
> Christophe Porteneuve a.k.a. TDD
> "[They] did not know it was impossible, so they did it." --Mark
Twain
> Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
new Ajax.Request(url, {
method: ''post'',
parameters: pars,
onComplete: function(transport) {
//currentPage = eval(''('' + json +
'')'');
//alert(''hello'');
//oUser = eval(''('' + response.responseText +
'')'');
//alert(oUser.FName);
//alert(json);
//alert(transport);
var json = transport.responseText.evalJSON(true);
//alert(json.FName);
//alert(json.LName);
//alert(json.EmailAddress);
//alert(json ? Object.inspect(json) : "no JSON object");
//alert(currentPage);
//$(''txtRefNotes'').value = ''hello'';
$(''txtRefFirstName'').value = json.FName;
$(''txtRefLastName'').value = json.LName;
$(''txtRefEmail'').value = json.EmailAddress;
$(''txtRefHomePhone'').value = json.Phone;
}
});
On 6/4/07, Mark Holton <holtonma-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> Hi Chris,
> Thanks for confirming. I found this (below) on an older thread and am
> going to try it in the a.m..... looks promising given what you have
> confirmed. Many thanks, (btw, like your BETA book. Bought it a couple
> weeks ago, been bogged down, but should get more into it in the next couple
> of weeks. Lots of good things in there I plan to review more than once.)
> thanks again and cheers,
> Mark
>
> "Yes. If your JSON is in the response body, you will have to evaluate
it
> yourself. It must be the framework you''re using which is creating
the
> X-JSON header, perhaps? For example:
>
> new Ajax.Request("some_page.cfm", {
> parameters: {id: 6},
> onComplete: function(transport) {
> var json = transport.responseText.evalJSON(true);
> /* ... do something else ... */
> }
> });
>
> You''re responseText should then be valid JSON. For more
information,
> see http://prototypejs.org/api/string/evaljson."
>
> On 6/4/07, Christophe Porteneuve
<tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:
> >
> >
> > Hey Mark,
> >
> > I always hated the guts out of this json parameter in the callbacks.
As
> >
> > explained in the docs (*cough*), it''s currently based on the
X-JSON
> > header, not the response''s body.
> >
> > You would need to use transport.responseText.evalJSON(true) instead.
> >
> > --
> > Christophe Porteneuve a.k.a. TDD
> > "[They] did not know it was impossible, so they did it."
--Mark Twain
> > Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org
> >
> > > >
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Chris,
This worked like a charm with 1.5.1, parsing JSON from the server
couldn''t have been simpler (note, doesn''t work in 1.5.0).
Thanks for
the reference to evalJSON.
cheers,
Mark
new Ajax.Request(url, {> method: ''post'',
> parameters: pars,
> onComplete: function(transport) {
>
> var json = transport.responseText.evalJSON(true);
>
> $(''txtRefFirstName'').value = json.FName;
> $(''txtRefLastName'').value = json.LName;
> $(''txtRefEmail'').value = json.EmailAddress;
> $(''txtRefHomePhone'').value = json.Phone;
> }
> });
On 6/4/07, Mark Holton <holtonma-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> Hi Chris,
> Thanks for confirming. I found this (below) on an older thread and am
> going to try it in the a.m..... looks promising given what you have
> confirmed. Many thanks, (btw, like your BETA book. Bought it a couple
> weeks ago, been bogged down, but should get more into it in the next couple
> of weeks. Lots of good things in there I plan to review more than once.)
> thanks again and cheers,
> Mark
>
> "Yes. If your JSON is in the response body, you will have to evaluate
it
> yourself. It must be the framework you''re using which is creating
the
> X-JSON header, perhaps? For example:
>
> new Ajax.Request("some_page.cfm", {
> parameters: {id: 6},
> onComplete: function(transport) {
> var json = transport.responseText.evalJSON(true);
> /* ... do something else ... */
> }
> });
>
> You''re responseText should then be valid JSON. For more
information,
> see http://prototypejs.org/api/string/evaljson."
>
> On 6/4/07, Christophe Porteneuve
<tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:
> >
> >
> > Hey Mark,
> >
> > I always hated the guts out of this json parameter in the callbacks.
As
> >
> > explained in the docs (*cough*), it''s currently based on the
X-JSON
> > header, not the response''s body.
> >
> > You would need to use transport.responseText.evalJSON(true) instead.
> >
> > --
> > Christophe Porteneuve a.k.a. TDD
> > "[They] did not know it was impossible, so they did it."
--Mark Twain
> > Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org
> >
> > > >
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---