Ajax Validation Failing for Chinese Characters

  • Thread starter Thread starter ngkamsengpeter
  • Start date Start date
  • Tags Tags
    Failing
Click For Summary

Discussion Overview

The discussion revolves around an issue with Ajax validation for usernames containing Chinese characters. Participants explore the problem of the validation failing for these characters, despite successful retrieval from the database upon form submission. The conversation touches on encoding issues and the differences between client-side and server-side processing.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant notes that the Ajax validation works for English characters but fails for Chinese characters, suggesting a potential encoding issue.
  • Another participant proposes that the response encoding may not match the actual content, recommending a focus on server-side handling.
  • A different viewpoint suggests that the problem lies in how the Ajax request is constructed, emphasizing the need for proper encoding of the request data.
  • Some participants discuss whether the issue is on the client side or server side, with one indicating that the encoding might be set incorrectly at some point in the process.
  • One participant expresses doubt about the encoding being the issue, citing successful echoing of Chinese characters before validation.
  • There is a request for clarification on how data is sent to the server, with confirmation that POST is being used.
  • Another participant emphasizes the importance of ensuring that PHP is properly receiving and formatting the data from the Ajax request.
  • Several requests for code examples are made to better understand the issue.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the root cause of the problem, with multiple competing views regarding whether the issue lies in encoding, client-side processing, or server-side handling.

Contextual Notes

There are unresolved questions regarding the specifics of the Ajax request construction and the handling of data on the server side, as well as the need for proper encoding practices.

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 .
 

Similar threads

  • · Replies 18 ·
Replies
18
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 16 ·
Replies
16
Views
6K
Replies
2
Views
3K
Replies
1
Views
8K