Ajax Validation Failing for Chinese Characters

  • Thread starter Thread starter ngkamsengpeter
  • Start date Start date
  • Tags Tags
    Failing
AI Thread Summary
The discussion revolves around an issue with using AJAX to validate usernames that contain Chinese characters. The user can successfully find the username in the database when submitting the form directly, but encounters problems when using AJAX for validation. The main concern is that the AJAX request may not be encoding the Chinese characters correctly, leading to failures in username validation. Participants suggest that the issue likely lies in the encoding process during the AJAX request, emphasizing the need for proper encoding of characters before sending them to the server. There is a consensus that ensuring the PHP server receives the data correctly formatted is crucial. The user confirms that the data appears correctly when echoed on the PHP side, indicating that the problem may not be with the server's response but rather with how the data is sent via AJAX. The conversation highlights the importance of encoding in AJAX requests and the need for proper data handling on both the client and server sides.
ngkamsengpeter
Messages
193
Reaction score
0
When I using Ajax to validate whether the username is exist my form , I can validate it when the username is in English character but when it is chinese character , it always can't find the username in my database eventhough the username is exist . However , when I submit the form , it can find the username in the database in chinese character . What it the problem ?
 
Technology news on Phys.org
probably response encoding does not match its actual content (chinese characters). I think you will have more luck in fighting it on server side.
 
whatta said:
probably response encoding does not match its actual content (chinese characters). I think you will have more luck in fighting it on server side.
What do you mean , you mean the response from mysql ? I think it is ok because it works when I submit the form but it don't works when using ajax which doesn't submit the form .What is the problem
 
No, I think whatta meant that since AJAX has to construct a request to the server manually, it's not encoding the request correctly. Make sure AJAX is correctly encoding it.

In AJAX, you have to manually encode everything, or use an appropriate encode function. For example, in AJAX you have to call encode to convert & to "&" or else PHP can not read it correctly.
 
Sane, I was under impression he has a problem on client side:
I using Ajax to validate whether the username is exist
But yes, when I think about it now, you could be right. It's hard to guess without any code given.
 
Whatta, what I had just finished describing was client side.

AJAX is client side. A request is client side. The client builds a request, with javascript, and sends this request to a server. That's AJAX.
 
what I had in mind is that it pulls list of names and verifies it in browser. what you seem to suggest is that it sends the username and server does verification.

either way, it seems that encoding is set wrong at some point inbetween.
 
I don't know how to encode it in the serverside .But I don't think is the encoding problem because I have tested it by placing an echo before validating process and it show the correct chinese words to me . Please help
 
How are you sending data to the server, via GET or POST?
 
  • #10
-Job- said:
How are you sending data to the server, via GET or POST?
Using post .
 
  • #11
Someone please help me .
 
  • #12
elaborate.
 
  • #13
whatta said:
elaborate.
what are you mean ?
 
  • #14
First thing you should focus on is ensuring PHP is properly receiving the data from the Ajax POST request. Is it properly formatted? On the javascript side did you escape the values using escape() before sending them to the PHP side via Ajax?
 
  • #15
i mean show us some code
 
  • #16
-Job- said:
First thing you should focus on is ensuring PHP is properly receiving the data from the Ajax POST request. Is it properly formatted? On the javascript side did you escape the values using escape() before sending them to the PHP side via Ajax?
I think it is propely formated because I echo it at the php side after receiving the data and it show correctly .
 
Back
Top