中文字符串在ajax请求后无法识别 [英] Chinese string can't be recognized after the ajax request

查看:518
本文介绍了中文字符串在ajax请求后无法识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个Ajax请求来POST数据。 webservice XML信息如下所示:

I write an Ajax request to POST the data. The webservice XML information is shown as below:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xmlns:xsd="http://www.w3.org/2001/XMLSchema"     xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
<AddNewStory xmlns="http://X.X.X.X/StoryForMac/">
  <StoryID>+story_id+</StoryID>
  <UserName>+User_Name+</UserName>
  <Story_CreateTime>+Story__CreateTime+</Story_CreateTime>
  <StoryName>+Story_Name+</StoryName>
</AddNewStory>
  </soap:Body>
</soap:Envelope>


        $.ajax({
            type: "POST",
            url: webServiceAddNewStoryImgUrl,
            contentType: "text/xml",
            dataType: "xml",
            data: soap_add_new_story_image,     
            success: process_update_pic_success,
            error: process_add_new_img_Error        
        }); 

我从文本文件中获取中文字符串,将其分配给变量Story_Name。
之后,我向webservice发出请求,但是中文字符串显示
????????。无论我输入什么,它只显示中文字符串?????....

I get the Chinese string from the text file, assigning it to the variable Story_Name. After this, I make a request to the webservice,but the Chinese string shows ????????. No matter what I input, it just shows the Chinese string "?????"....

如我所知,在webservice上声明的字符串在C#中)编码为Unicode,并且JavaScript字符串也编码为UTF-8(?)。
我无法弄清楚为什么会发生这种情况。

我做了一个测试:我在webservice上运行调试器并直接输入中文字符串。这一次,它显示正确!

为什么会发生?

As I know, the string declared on the webservice(implemented in C#) is encoded as Unicode, and the javascript string is encoded UTF-8(?) as well.
I can't figure it out why this happened.
I made a test: I run the debugger on the webservice and input Chinese string directly. This time, it shows correctly !!
Why this happened?


ps:我创建的应用程序基于Android系统,我使用PhoneGap API来读取移动设备上的字符串。

任何建议


ps: I create the application based on the Android system and I use PhoneGap API to read the string on the mobile device.
Any suggestion??


任何帮助或建议,请。


ANY HELP OR SUGGESTION, PLEASE. I HAVE SPENT SEVERAL DAYS IN THIS ISSUE, TRYING LOTS OF METHOD, BUT ALL IN VAIN.

推荐答案

这里有一个例子Shown @ http://www.webtoolkit.info/javascript-utf8.html

There is an example Shown @ http://www.webtoolkit.info/javascript-utf8.html

- 谢谢

这篇关于中文字符串在ajax请求后无法识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆