473,324 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

problem with sending json encoded data via ajax to a php script(internationalization)

Hi,

I am using javascript to collect the user input from a form, put it in
an object, json encode it (using JSON or YUI JSON), use the YUI
connection manager (XMLHTTPRequest) to send it to a PHP script for
validation after a json_decode; result an associative array. The
webpage (valid XHTML), the PHP script, the Apache webserver, the mysql
db server all use charset utf-8.

It works ok for normal text, problems began when one of the input
fields contained coordinates (56°17'16'', it is supposed to contain
coordinates), the PHP script could not json_decode the data send by
IE7 (no problem with FF, Opera and Safari).
When the user input contains an &, then the PHP script cannot not
json_decode it, no error message, just an empty array.

I guess the solution might be in the use of escape (javascript) and
urldecode (PHP), but I have not succeeded in making it work yet. Do
you use those functions and the data you send, on the querystring or
on the complete url? Other problem is that escape and urldecode are
not an exact match.

Pugi!
Jan 9 '08 #1
1 3503
Pugi! said:
I guess the solution might be in the use of escape (javascript) and
urldecode (PHP), but I have not succeeded in making it work yet. Do
you use those functions and the data you send, on the querystring or
on the complete url? Other problem is that escape and urldecode are
not an exact match.
use encodeURIComponent in javascript before you assemble as JSON, and
then send it via post through the XHR.

use XMLHttpRequest.setRequestHeader(
"Content-Type", "application/x-www-form-urlencoded")

To set up your XHR for POST, then assemble the data you want to send in
this format:

"name=value&name2=value2&....nameN=valueN"

And where you would normally send null in your XHR, send the data instead.

The great thing about encodeURIComponent() is that all that translation
is done at the server level on most servers (all the ones I've ever
worked on), so once it gets to PHP, it should be okie doke.

If not, contact me privately (the email is in my sig), and we can talk
about the PHP side, this isn't the place for that.

All the best,
~A!

--
anthony at my pet programmer dot com
Jan 9 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Brian Kelley | last post by:
I have been using gettext and various utilities to provide internationalization for a wxPython application and have not really been liking the process. Essentially it uses a macro-style notation...
8
by: wael | last post by:
hello all, i want convert w_char to UCS2 encoded (0041) this is a char encoded UCS2 please look at this http://www.unicode.org/charts/ http://www.unicode.org/ every language has a chart bye...
12
by: Chris Mullins | last post by:
I'm implementing RFC 3491 in .NET, and running into a strange issue. Step 1 of RFC 3491 is performing a set of mappings dicated by tables B.1 and B.2. I'm having trouble with the following...
0
by: Pablo Jose Almeida da Guia | last post by:
Well.. ...I am using some resource files to make the internationalization of a ASP.NET application. I created a project and three resource files. ------- resource files ------- /strings.txt...
3
by: Jules | last post by:
i'm working with translators that just want to translate "web pages" and not deal with resource files. i'd like to have a file structure that looks sort of like this: / <- root directory where...
1
by: muzilli | last post by:
Howdy all, somebody used in the past the library System.Resources for internationalization purpose? I would like to develop an application multi-lingual (english and french) and I´m thinking...
3
by: Hugh Oxford | last post by:
Can anyone recommend an approach to internationalization? I am specifically concerned about the need to append an &lang=xx to every internal link and URL. I really don't want to have to manually...
12
by: Juan T. Llibre | last post by:
re: !I found an MSDN document that explains why what I'm trying to do should work Lee, From : http://www.w3.org/TR/REC-xml/ "A special attribute named xml:lang may be inserted in...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.