Ajax Validation Failing for Chinese Characters

  • Thread starter ngkamsengpeter
  • Start date
  • Tags
    Failing
In summary: But what are you mean by "properly formatted"? Do you think it's something with the data itself or with how PHP is receiving it?
  • #1
ngkamsengpeter
195
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
  • #2
probably response encoding does not match its actual content (chinese characters). I think you will have more luck in fighting it on server side.
 
  • #3
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
 
  • #4
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.
 
  • #5
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.
 
  • #6
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.
 
  • #7
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.
 
  • #8
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
 
  • #9
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 .
 

1. Why is Ajax validation failing for Chinese characters?

Ajax validation may fail for Chinese characters due to encoding issues. Since Chinese characters are not recognized by the default UTF-8 encoding, they may be converted to question marks or other symbols, causing the validation to fail.

2. How can I fix Ajax validation failing for Chinese characters?

You can fix Ajax validation failing for Chinese characters by setting the correct encoding in your HTML document. You can use the meta tag <meta charset="UTF-8"> to specify the character encoding for your document, including Chinese characters.

3. Can I use a different encoding for Chinese characters if I don't want to change my overall encoding?

Yes, you can specify a different encoding for Chinese characters only by using the <meta charset="UTF-8"> tag. This will ensure that Chinese characters are recognized and validated correctly, while keeping your overall document encoding the same.

4. I am using a library for Ajax validation, but it still fails for Chinese characters. Why?

Some libraries may not support Chinese characters by default, and may require additional configuration or libraries to handle them properly. You may need to consult the documentation or seek help from the library's support team to resolve the issue.

5. Is there a way to validate Chinese characters without using Ajax?

Yes, you can validate Chinese characters without using Ajax by using server-side validation. This involves sending the form data to the server and validating it using a server-side language like PHP or Java. This allows for greater control and flexibility in handling Chinese characters and other special characters.

Similar threads

  • Programming and Computer Science
Replies
18
Views
2K
  • Programming and Computer Science
Replies
5
Views
3K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
551
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
11
Views
995
  • Programming and Computer Science
Replies
1
Views
7K
  • Biology and Chemistry Homework Help
Replies
1
Views
628
Back
Top