asp.net solve js pass parameter, the URL character garbled problem
Today, write the program, using jquery to submit data, in which the path has Chinese parameters, in JS alert out is Chinese, but submitted to the server side has become garbled. The cause of the problem is coding.
In my program, jquery uses this form to request data from the server:
$.get ("Users.aspx?name=" +name,null,function (data) {
$ ("#result"). HTML (data);
});
Using jquery or knowing Ajax, this is the server-side request written in JS when using jquery for Ajax, and the parameter name contains Chinese, that is, this parameter is submitted to the server side is garbled.
The solution is:
$.get ("Users.aspx?name=" Encodeurl (Encodeurl (Uaername)), null,function (data)) {
$ ("#result"). HTML (data);
});
Double-encodeURI code for name. After the server side:
String username= request["name". ToString ();
Username=server.urldecode (username);
The problem is solved.