I'm trying to do something that is probably very basic for most.

I'm trying to send an Ajax.Request while validating a form.  I'd like
a JSON response like this:

{success: true, htmlCode: "blah, blah, blah"}

Help is always greatly appreciated.




Attempt
1 
........................................................................................................

This sends back the right response, but I can't parse it so that I
know it was successful and then use the htmlCode.  It just updates the
div tag with the entire JSON response.


            function ajaxRequest(){
                var url = "/cgidev2p/r_chgpwd.pgm";
                var pars = 'v_current=' + escape($F('v_current')) +
'&v_new=' + escape($F('v_new')) + '&v_confirm=' + escape($F
('v_confirm')) + '&sessionid=' + escape($F('sessionid'));
                var target = 'v_messege';
                var ajaxObjhttp = new Ajax.Request(url, {
                    method: 'post',
                    parameters: pars,
                    onCreate: function(transport){
                        var myAjax = new Ajax.Updater(target, url, {
                            method: 'get',
                            parameters: pars
                        });
                        //alert("Creating New Ajax Call");
                    },
                    onSuccess: function(transport){
                        var json = transport.responseText.evalJSON();
                        var submitObj = document.getElementById
('goButton');
                        if (json.success) {
                            submitObj.disabled = false;
                            document.getElementById('goButton').focus;
                        }
                        else {
                            submitObj.disabled = true;
                        }
                    }
                });
            }


Attempt
2 
........................................................................................................

I think this is more what I need.  It makes the request, but again I
don't know how to handle the json coming back so that I know if it was
successful and then use the second parm.

            function ajaxRequest2(){
                var url = "/cgidev2p/r_chgpwd.pgm";
                var pars = 'v_current=' + escape($F('v_current')) +
'&v_new=' + escape($F('v_new')) + '&v_confirm=' + escape($F
('v_confirm')) + '&sessionid=' + escape($F('sessionid'));
                new Ajax.Request(url, {
                    method: 'get',
                    parameters: pars,
                    onSuccess: function(transport){
                        var json = transport.responseText.evalJSON
(true);
                        //  v_messege.update(json).setStyle
({ background: '#dfd' });
                        alert(json);
                    }
                });
            }



--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to