[Proto-Scripty] Re: ajax request no works on Chrome - decoding fails
Hi, It's T.J., not J. i want convert requestObject in JSON string and send to the server. var jsonRequest = encodeURIComponent(JSON.stringify(requestObject)); new Ajax.Request(baseUrl + '/usermsg/index/sendmessage', { method: 'POST', requestHeaders: {Accept: 'application/json'}, parameters: jsonRequest, //... Let's look at the code I gave you before AGAIN: var jsonRequest = ...; new Ajax.Request( // ... parameters: {json: jsonRequest} // ... }); As you can see, I used jsonRequest. I did that for a reason, so it would fit in with your original code, which did this: var jsonRequest = JSON.stringify(requestObject); So: 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: {json: jsonRequest}, // === CHANGE IS HERE onSuccess: function(transport, json) { //use and handle foo response data } , on500: function(transport) { //handle error, inform user }, onComplete: parseSendMessage }); } // ...your code left off here That tells Prototype to do any URI-encoding necessary for you (you still have to stringify the object first, which is why I used jsonRequest, not requestObject). It sends a nice, normal URL-encoded request (technically an application/x-www-form-urlencoded POST) to the server with a single form field, 'json', whose value is the URL- encoded jsonRequest string. Having done that, you ALSO have to change the server side to retrieve and un-JSON that form field: $request = $_POST[json]; $requestObject = Zend_Json::decode($request); // Or your $zendJson, whatever that is Now again, this is not the only way to do it. It's _possible_ to send pure JSON without doing the form wrapper around it as I've done above (in which case you probably wouldn't URL-encode at all, because you wouldn't be sending URL-encoded data). You can send any content type you like with a POST. If you're not sending data in the application/x- www-form-urlencoded encoding, you have to specify what you're doing by setting the Content-Type header (for pure JSON, it would be application/json). You have to handle issues like ensuring there's a carriage return every couple of hundred characters and such (because of links in the chain that may handle HTTP poorly). But whenever possible, I stick to sending standard forms, because they're convenient and reliable across browsers and servers. Forms (that is, POST requests with the content type application/x-www-form- urlencoded) are well-tested, and well-supported by frameworks. Since you appear to be in control of both the client and server sides of what you're building, I'd probably stick with sending a form containing a field with the JSON in it, rather than going through the hassle of sending JSON without a form wrapper around it. Hope this helps, -- T.J. On Nov 11, 12:49 am, fashionpeople fashionpeople.busin...@gmail.com wrote: J. Crowder do not get me wrong, I thank you for the effort they put in helping others. i readed about your suggest to send data in this simple way: var jsonRequest = ...; new Ajax.Request( // ... parameters: {json: jsonRequest} // ... }); but my question is, i have all based application such statements: var requestObject = new Object(); requestObject.idNickRcv = idNickRcv; requestObject.msg = msg; i want convert requestObject in JSON string and send to the server. var jsonRequest = encodeURIComponent(JSON.stringify(requestObject)); new Ajax.Request(baseUrl + '/usermsg/index/sendmessage', { method: 'POST', requestHeaders: {Accept: 'application/json'}, parameters: jsonRequest, //... In this way works only IE and FireWorks. Not on Chrome always decoding fails. you must use stringify? scriptaculous encodes them alone? Thank you -- 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
[Proto-Scripty] Re: ajax request no works on Chrome - decoding fails
Hi T.J. Crowder, var jsonRequest = JSON.stringify(requestObject); new Ajax.Request(baseUrl + '/usermsg/index/sendmessage', { method: 'POST', requestHeaders: {Accept: 'application/json'}, parameters: {json: jsonRequest}, // ... In PHP: $request = $this-getRequest(); $json= $request-getParam(json); // HERE decode fails with data sended from chrome $requestObject = $zendJson-decode($json, Zend_Json::TYPE_OBJECT); With Chrome decoding fails too. Why? :\ On 11 Nov, 03:47, T.J. Crowder t...@crowdersoftware.com wrote: Hi, It's T.J., not J. i want convert requestObject in JSON string and send to the server. var jsonRequest = encodeURIComponent(JSON.stringify(requestObject)); new Ajax.Request(baseUrl + '/usermsg/index/sendmessage', { method: 'POST', requestHeaders: {Accept: 'application/json'}, parameters: jsonRequest, //... Let's look at the code I gave you before AGAIN: var jsonRequest = ...; new Ajax.Request( // ... parameters: {json: jsonRequest} // ... }); As you can see, I used jsonRequest. I did that for a reason, so it would fit in with your original code, which did this: var jsonRequest = JSON.stringify(requestObject); So: 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: {json: jsonRequest}, // === CHANGE IS HERE onSuccess: function(transport, json) { //use and handle foo response data } , on500: function(transport) { //handle error, inform user }, onComplete: parseSendMessage }); } // ...your code left off here That tells Prototype to do any URI-encoding necessary for you (you still have to stringify the object first, which is why I used jsonRequest, not requestObject). It sends a nice, normal URL-encoded request (technically an application/x-www-form-urlencoded POST) to the server with a single form field, 'json', whose value is the URL- encoded jsonRequest string. Having done that, you ALSO have to change the server side to retrieve and un-JSON that form field: $request = $_POST[json]; $requestObject = Zend_Json::decode($request); // Or your $zendJson, whatever that is Now again, this is not the only way to do it. It's _possible_ to send pure JSON without doing the form wrapper around it as I've done above (in which case you probably wouldn't URL-encode at all, because you wouldn't be sending URL-encoded data). You can send any content type you like with a POST. If you're not sending data in the application/x- www-form-urlencoded encoding, you have to specify what you're doing by setting the Content-Type header (for pure JSON, it would be application/json). You have to handle issues like ensuring there's a carriage return every couple of hundred characters and such (because of links in the chain that may handle HTTP poorly). But whenever possible, I stick to sending standard forms, because they're convenient and reliable across browsers and servers. Forms (that is, POST requests with the content type application/x-www-form- urlencoded) are well-tested, and well-supported by frameworks. Since you appear to be in control of both the client and server sides of what you're building, I'd probably stick with sending a form containing a field with the JSON in it, rather than going through the hassle of sending JSON without a form wrapper around it. Hope this helps, -- T.J. On Nov 11, 12:49 am, fashionpeople fashionpeople.busin...@gmail.com wrote: J. Crowder do not get me wrong, I thank you for the effort they put in helping others. i readed about your suggest to send data in this simple way: var jsonRequest = ...; new Ajax.Request( // ... parameters: {json: jsonRequest} // ... }); but my question is, i have all based application such statements: var requestObject = new Object(); requestObject.idNickRcv = idNickRcv; requestObject.msg = msg; i want convert requestObject in JSON string and send to the server. var jsonRequest = encodeURIComponent(JSON.stringify(requestObject)); new Ajax.Request(baseUrl + '/usermsg/index/sendmessage', {
Re: [Proto-Scripty] Re: ajax request no works on Chrome - decoding fails
On Nov 11, 2010, at 8:20 AM, fashionpeople wrote: Hi T.J. Crowder, var jsonRequest = JSON.stringify(requestObject); new Ajax.Request(baseUrl + '/usermsg/index/sendmessage', { method: 'POST', requestHeaders: {Accept: 'application/json'}, parameters: {json: jsonRequest}, // ... In PHP: $request = $this-getRequest(); $json= $request-getParam(json); // HERE decode fails with data sended from chrome $requestObject = $zendJson-decode($json, Zend_Json::TYPE_OBJECT); With Chrome decoding fails too. Why? :\ Can you print out the raw value of your $json string after the getParam call? Then echo a few paragraph returns and also print the raw value of $_POST['json']. You have two different black boxes here -- getParam() and $zendJson- decode(). Either one of these may be helping you by decoding some part of the variable posted by Prototype. You may be double-decoding something, or missing the decode on something else. Try printing the raw text to the screen each time and see what and where the value changes in your server-side. It's unlikely that encodeURIComponent is different between two browsers. There may indeed be some other part of Prototype that is over-correcting some encoding on the browser side, based on a mis- reading of the user agent or some other variable. But I would button down the server side first, and make sure that you are getting the very same raw data in and that your conversions are proceeding in a normal fashion within the PHP domain. If two browsers send two different raw POST bodies, then you're right -- the issue is within Prototype, or maybe within the browser and Prototype isn't spackling over it the way it usually does. You may also have found a difference of opinion between PHP JSON and JS JSON -- these do exist and they are very annoying and require hunt- and-peck application of addslashes() and stripslashes(). Which reminds me -- do look at the current value of magic_quotes_gpc, both on your server and within your application. That's another snake-pit I have had to cross with JSON on PHP. Walter On 11 Nov, 03:47, T.J. Crowder t...@crowdersoftware.com wrote: Hi, It's T.J., not J. i want convert requestObject in JSON string and send to the server. var jsonRequest = encodeURIComponent(JSON.stringify(requestObject)); new Ajax.Request(baseUrl + '/usermsg/index/sendmessage', { method: 'POST', requestHeaders: {Accept: 'application/json'}, parameters: jsonRequest, //... Let's look at the code I gave you before AGAIN: var jsonRequest = ...; new Ajax.Request( // ... parameters: {json: jsonRequest} // ... }); As you can see, I used jsonRequest. I did that for a reason, so it would fit in with your original code, which did this: var jsonRequest = JSON.stringify(requestObject); So: 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: {json: jsonRequest}, // === CHANGE IS HERE onSuccess: function(transport, json) { //use and handle foo response data } , on500: function(transport) { //handle error, inform user }, onComplete: parseSendMessage }); } // ...your code left off here That tells Prototype to do any URI-encoding necessary for you (you still have to stringify the object first, which is why I used jsonRequest, not requestObject). It sends a nice, normal URL-encoded request (technically an application/x-www-form-urlencoded POST) to the server with a single form field, 'json', whose value is the URL- encoded jsonRequest string. Having done that, you ALSO have to change the server side to retrieve and un-JSON that form field: $request = $_POST[json]; $requestObject = Zend_Json::decode($request); // Or your $zendJson, whatever that is Now again, this is not the only way to do it. It's _possible_ to send pure JSON without doing the form wrapper around it as I've done above (in which case you probably wouldn't URL-encode at all, because you wouldn't be sending URL-encoded data). You can send any content type you like with a POST. If you're not sending data in the application/x- www-form-urlencoded encoding, you have to specify what you're doing by setting the Content-Type
[Proto-Scripty] Re: ajax request no works on Chrome - decoding fails
Hi T.J. Crowder, Now works with your suggests. Thanks a lot. The ajax request look like doesn't work, because callback parse, it did call another ajax request not fixed with your suggets. Thanks. On 11 Nov, 15:43, Walter Lee Davis wa...@wdstudio.com wrote: On Nov 11, 2010, at 8:20 AM, fashionpeople wrote: Hi T.J. Crowder, var jsonRequest = JSON.stringify(requestObject); new Ajax.Request(baseUrl + '/usermsg/index/sendmessage', { method: 'POST', requestHeaders: {Accept: 'application/json'}, parameters: {json: jsonRequest}, // ... In PHP: $request = $this-getRequest(); $json = $request-getParam(json); // HERE decode fails with data sended from chrome $requestObject = $zendJson-decode($json, Zend_Json::TYPE_OBJECT); With Chrome decoding fails too. Why? :\ Can you print out the raw value of your $json string after the getParam call? Then echo a few paragraph returns and also print the raw value of $_POST['json']. You have two different black boxes here -- getParam() and $zendJson- decode(). Either one of these may be helping you by decoding some part of the variable posted by Prototype. You may be double-decoding something, or missing the decode on something else. Try printing the raw text to the screen each time and see what and where the value changes in your server-side. It's unlikely that encodeURIComponent is different between two browsers. There may indeed be some other part of Prototype that is over-correcting some encoding on the browser side, based on a mis- reading of the user agent or some other variable. But I would button down the server side first, and make sure that you are getting the very same raw data in and that your conversions are proceeding in a normal fashion within the PHP domain. If two browsers send two different raw POST bodies, then you're right -- the issue is within Prototype, or maybe within the browser and Prototype isn't spackling over it the way it usually does. You may also have found a difference of opinion between PHP JSON and JS JSON -- these do exist and they are very annoying and require hunt- and-peck application of addslashes() and stripslashes(). Which reminds me -- do look at the current value of magic_quotes_gpc, both on your server and within your application. That's another snake-pit I have had to cross with JSON on PHP. Walter On 11 Nov, 03:47, T.J. Crowder t...@crowdersoftware.com wrote: Hi, It's T.J., not J. i want convert requestObject in JSON string and send to the server. var jsonRequest = encodeURIComponent(JSON.stringify(requestObject)); new Ajax.Request(baseUrl + '/usermsg/index/sendmessage', { method: 'POST', requestHeaders: {Accept: 'application/json'}, parameters: jsonRequest, //... Let's look at the code I gave you before AGAIN: var jsonRequest = ...; new Ajax.Request( // ... parameters: {json: jsonRequest} // ... }); As you can see, I used jsonRequest. I did that for a reason, so it would fit in with your original code, which did this: var jsonRequest = JSON.stringify(requestObject); So: 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: {json: jsonRequest}, // === CHANGE IS HERE onSuccess: function(transport, json) { //use and handle foo response data } , on500: function(transport) { //handle error, inform user }, onComplete: parseSendMessage }); } // ...your code left off here That tells Prototype to do any URI-encoding necessary for you (you still have to stringify the object first, which is why I used jsonRequest, not requestObject). It sends a nice, normal URL-encoded request (technically an application/x-www-form-urlencoded POST) to the server with a single form field, 'json', whose value is the URL- encoded jsonRequest string. Having done that, you ALSO have to change the server side to retrieve and un-JSON that form field: $request = $_POST[json]; $requestObject = Zend_Json::decode($request); // Or your $zendJson, whatever that is Now again, this is not the only way
[Proto-Scripty] Re: ajax request no works on Chrome - decoding fails
Hi, I tried use fixedEncodeURI like suggest in your links. I've never even heard of fixedEncodeURI. People are taking the time to help you here, it's worth taking the time to carefully *read* what people have written and try the things they suggest (or not, of course, it's up to you). This is what I've suggested that you haven't, as far as I can tell, tried: On Nov 8, 9:42 pm, T.J. Crowder t...@crowdersoftware.com wrote: 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 Good luck with it, -- T.J. On Nov 9, 11:37 pm, fashionpeople fashionpeople.busin...@gmail.com wrote: I tried use fixedEncodeURI like suggest in your links. But doesn't work. I didn't understand the problem. On 9 Nov, 17:25, T.J. Crowder t...@crowdersoftware.com wrote: 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
[Proto-Scripty] Re: ajax request no works on Chrome - decoding fails
It may be helping if you could trace and post here the following things : From Javascript: - requestObject - JSON.stringify(requestObject) From PHP: - $this-getRequest()-getRawBody(); - rawurldecode($this-getRequest()-getRawBody()); Also, why do you need to use JSON.stringify thing when, as T.J. told you (twice) prototype is designed to take care of it for you. Eric On 10 nov, 00:37, fashionpeople fashionpeople.busin...@gmail.com wrote: I tried use fixedEncodeURI like suggest in your links. But doesn't work. I didn't understand the problem. On 9 Nov, 17:25, T.J. Crowder t...@crowdersoftware.com wrote: 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 } ,
[Proto-Scripty] Re: ajax request no works on Chrome - decoding fails
J. Crowder do not get me wrong, I thank you for the effort they put in helping others. i readed about your suggest to send data in this simple way: var jsonRequest = ...; new Ajax.Request( // ... parameters: {json: jsonRequest} // ... }); but my question is, i have all based application such statements: var requestObject = new Object(); requestObject.idNickRcv = idNickRcv; requestObject.msg = msg; i want convert requestObject in JSON string and send to the server. var jsonRequest = encodeURIComponent(JSON.stringify(requestObject)); new Ajax.Request(baseUrl + '/usermsg/index/sendmessage', { method: 'POST', requestHeaders: {Accept: 'application/json'}, parameters: jsonRequest, //... In this way works only IE and FireWorks. Not on Chrome always decoding fails. you must use stringify? scriptaculous encodes them alone? Thank you -- 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.
[Proto-Scripty] Re: ajax request no works on Chrome - decoding fails
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
[Proto-Scripty] Re: ajax request no works on Chrome - decoding fails
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
[Proto-Scripty] Re: ajax request no works on Chrome - decoding fails
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
[Proto-Scripty] Re: ajax request no works on Chrome - decoding fails
I tried use fixedEncodeURI like suggest in your links. But doesn't work. I didn't understand the problem. On 9 Nov, 17:25, T.J. Crowder t...@crowdersoftware.com wrote: 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
[Proto-Scripty] Re: ajax request no works on Chrome - decoding fails
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-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.
Re: [Proto-Scripty] Re: ajax request no works on Chrome - decoding fails
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 at http://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.