javascript - Posting JSON string using dojo.xhrPost - Stack Overflow

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

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, and from their examples this should work.

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

Thanks,

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, and from their examples this should work.

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

Thanks,

Share Improve this question edited Aug 12, 2010 at 7:29 bakkal 55.5k12 gold badges136 silver badges113 bronze badges asked Aug 4, 2010 at 14:18 Grant CollinsGrant Collins 1,7915 gold badges31 silver badges47 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

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

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745301631a4621468.html

相关推荐

  • javascript - Posting JSON string using dojo.xhrPost - Stack Overflow

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

    8小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信