views:

33

answers:

2

Hi,

I am having an issue trying to post a JSON string using dojo.xhrPost to a Zend Framework Controller.

When I post the string to the server I get no data being sent. I've even tried just sending "A Test string", even that is not being sent.

I've done a var dump to see the contents of the request but clear as day, there is no parameter or data of what I am posting. My code looks like this:

var jsonStr = dojo.toJson(values);
var xhrArgs = ({
        url:"/dojo/savedetails/",
        postData: jsonStr,
        handleAs: "text",               
        load: function(data){

            if(data == 'success'){

                //success code
               dojo.byId('edit_alert').innerHTML = '<div class="info">Your changes have been saved</div>'

            }else{

                dojo.byId('edit_alert').innerHTML = '<div class="error">We were unable to save your changes please try again.</div>';
            }

        }           

    });

    //we now post the data to the server for processing.
    var deferred = dojo.xhrPost(xhrArgs);

The contents of my var_dump($this->_request) is:

object(Zend_Controller_Request_Http)#118 (14) { ["_paramSources":protected]=>  
array(2) { [0]=>  string(4) "_GET" [1]=>  string(5) "_POST" } ["_requestUri":protected]=>  string(25) "/dojo/savedetails/" 
["_baseUrl":protected]=>  string(0) "" ["_basePath":protected]=>  NULL ["_pathInfo":protected]=>  string(25) "/dojo/savedetails/" ["_params":protected]=>
array(3) { ["controller"]=>  string(4) "dojo" ["action"]=>  string(18) "savedetails" ["module"]=>  string(7) "default" } ["_aliases":protected]=>  array(0)
{ } ["_dispatched":protected]=>  bool(true) ["_module":protected]=>  string(7) "default" ["_moduleKey":protected]=>  string(6) "module" 
["_controller":protected]=>  string(4) "dojo" ["_controllerKey":protected]=>  string(10) "controller" ["_action":protected]=>  
string(18) "savedetails" ["_actionKey":protected]=>  string(6) "action" } 

I hope that I am missing something simple however I've been following the documentation on dojotoolkit.org, and from their examples this should work.

I'm Using Dojo 1.3 and Zend Framework 1.9 if that helps.

Thanks,

A: 

If you use postData to pass in the content, you need to use dojo.rawXhrPost instead of dojo.xhrPost.

Alex Cheng
A: 

Try content instead of postData. Also, load up Firebug (firefox), Developer Tools (chrome/IE), or Fiddler and see what the actual outgoing HTTP request looks like.