var data = {
Username:escape (your user name here),
Password:escape (your password),
};
var jsonstr = json.stringify (data); The Json2 method.
$.ajax ({
URL: '.. /service.asmx/login ',
Data: ' userinfo= ' + jsonstr,
ContentType: "Application/json; Charset=utf-8 ",
DataType: "Jsonp",
Type: "Get",
Success:function (response) {
...
},
Error:function (A, B, c) {
...
}
});
The
scenario is to encode the Chinese character by using the escape method of the Web effect, and then go to WebService to decode it automatically.
There is another problem today: using jquery ajax get to send Unicode characters such as Swedish characters is garbled, even with escape.
Think: A request sent through a GET method actually transmits the parameter through a URI, so the character transferred by get is independent of the encoding format of the file, and it is entirely up to the URI to decide what to transmit, so what if the URI is encoded?
In fact, JavaScript already has such a global function to encode the URI: encodeURI (URI), so that jquery Ajax sent a data encoded by the URI will not appear garbled, And the data can be decode automatically at the WebService end.
The improved code is as follows:
var data = {
username:encodeuri (your user name here),
&nbs p; Password:encodeuri (your password here),
};
var jsonstr = json.stringify (data); //The Json2 method.
$.ajax ({
URL: ' ... /service.asmx/login ',
data: ' userinfo= ' + jsonstr,
ContentType: "Application/json; Charset=utf-8 ",
datatype:" Jsonp ",
Type:" Get ",
& nbsp; success:function (response) {
...
},
error:function (A, B, c) {
& nbsp; ...
}
});