Hi, > I replaced escape with encodeURI. But decoding fails again.
Well, did you try actually doing what I suggested? -- T.J. On Nov 9, 4:07 pm, fashionpeople <fashionpeople.busin...@gmail.com> wrote: > Hi, > > I replaced escape with encodeURI. But decoding fails again. > > function sendMessage(baseUrl, idNickRcv, msg) { > > var requestObject = new Object(); > requestObject.idNickRcv = idNickRcv; > requestObject.msg = msg; > > var jsonRequest = JSON.stringify(requestObject); > > if ((idNickRcv) && (msg)) { > > new Ajax.Request(baseUrl + '/usermsg/index/sendmessage', { > method: 'POST', > requestHeaders:{ Accept:'application/json' }, > parameters: encodeURI(jsonRequest), > > onSuccess: > function(transport, json) { > //use and handle foo response data > } > , > on500: > function(transport) { > //handle error, inform user > }, > onComplete: parseSendMessage > > }); > > } > > php: > > $request = rawurldecode($this->getRequest()- > > >getRawBody()); > > // HERE DECODING FAILS AND EXECUTION IS INTERRUPTED. > $requestObject = $zendJson->decode($request, > Zend_Json::TYPE_OBJECT); > $msg = $requestObject->msg; > $idNickRcv = $requestObject->idNickRcv; > > On 8 Nov, 23:11, Walter Lee Davis <wa...@wdstudio.com> wrote: > > > > > > > > > Right. The best low-level way to translate JS to PHP and back again is > > using encodeURI or uncodeURIComponent on your JS side, and > > rawurldecode() or rawurlencode() on the PHP side. They are > > functionally identical, as long as you have set your PHP side to use > > UTF-8 as its default charset. > > > Walter > > > On Nov 8, 2010, at 4:42 PM, T.J. Crowder wrote: > > > > Hi, > > > > I don't know that it's the problem because I'm not a PHP person, but > > > you're using the `escape` function to encode your parameters, and then > > > decoding them with a PHP function called `urldecode`. JavaScript's > > > `escape` function does _not_ URL-encode things, it does something > > > similar but different and is almost certainly not what you want. I'm > > > surprised it's working with other browsers, frankly, but perhaps > > > that's my lack of PHP knowledge. > > > > The most reliable way to send parameters that I know is to send them > > > URL-encoded, and to decode them as URL-encoded data. In Prototype, the > > > easiest way to do that is to supply a plain object to the Ajax.Request > > > method (which Prototype will correctly encode for you): > > > > var jsonRequest = ...; > > > new Ajax.Request( // ... > > > parameters: {json: jsonRequest} > > > // ... > > > }); > > > > ...and then retrieve the value just as you would any other value: > > > > $request = $_POST["json"]; > > > $requestObject = Zend_Json::decode($request); // Or your > > > $zendJson, whatever that is > > > > But again, I'm not a PHP guy and could easily be missing something > > > important here. > > > > FWIW, > > > -- > > > T.J. Crowder > > > Independent Software Engineer > > > tj / crowder software / com > > > www / crowder software / com > > > > On Nov 8, 5:47 pm, fashionpeople <fashionpeople.busin...@gmail.com> > > > wrote: > > >> Hi, > > > >> this is my ajax request that works perfectly on IE and FIREFOX, but > > >> not in CHROME! > > > >> function sendMessage(baseUrl, idNickRcv, msg) { > > > >> var requestObject = new Object(); > > >> requestObject.idNickRcv = idNickRcv; > > >> requestObject.msg = msg; > > > >> var jsonRequest = JSON.stringify(requestObject); > > > >> if ((idNickRcv) && (msg)) { > > > >> new Ajax.Request(baseUrl + '/usermsg/index/sendmessage', { > > >> method: 'POST', > > >> requestHeaders:{ Accept:'application/json' }, > > >> parameters: escape(jsonRequest), > > > >> onSuccess: > > >> function(transport, json) { > > >> //use and handle foo response data > > >> } > > >> , > > >> on500: > > >> function(transport) { > > >> //handle error, inform user > > >> }, > > >> onComplete: parseSendMessage > > > >> }); > > > >> } > > > >> the problem is in action side server. > > >> there is this PHP / ZEND FRAMEWORK code: > > > >> .... > > > >> $request = urldecode($this->getRequest()- > > >> >getRawBody()); > > > >> $requestObject = $zendJson->decode($request, > > >> Zend_Json::TYPE_OBJECT); > > > >> .... > > > >> Json decoding fails with Syntax Error, for this reason Ajax request > > >> no > > >> works and is interrupted. > > >> Chrome send a bad json string! > > > >> Any suggests? > > > > -- > > > 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 > > > prototype-scriptaculous@googlegroups.com > > > . > > > To unsubscribe from this group, send email to > > > prototype-scriptaculous+unsubscr...@googlegroups.com > > > . > > > For more options, visit this group > > > athttp://groups.google.com/group/prototype-scriptaculous?hl=en > > > . -- 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 prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.