我用easyui datagrid顯示一個表的數據,點擊添加或者修改按鈕時會彈出dialog的對話框,前台都能正確的拿到值,但是傳到後台的時候,只要是中文的都變成了亂碼。這是怎麼回事??
給你們看一下我的代碼
var toolbar = [{
text: '添加',
iconCls: 'icon-add',
handler: function () {
$("#divadd").show();
$("#divadd").dialog({
title: '添加',
width: 300,
height: 300,
closed: false,
cache: false,
modal: true,
buttons:[{
text: '保存',
iconCls: 'icon-save',
handler: function () {
var loginid = $("#txtLoginId").val();
var LoginPwd = $("#txtLoginPwd").val();
var UserStateId = $("#txtUserStateId").val();
var TeacherName = $("#txtTeacherName").val();
var Sex = $('#txtSex').datebox('getValue');
var Birthday = $('#txtBirthday').datebox('getValue');
$.ajax({
url: "Handler.ashx?type=2&loginId=" + loginid + "&LoginPwd=" + LoginPwd + "&UserStateId=" + UserStateId + "&TeacherName=" + TeacherName + "&Sex=" + Sex + "&Birthday=" + Birthday,
success: function (data) {
if (data == "ok") {
$.messager.alert("系統提示", "數據添加成功!");
showDate();
$('#divadd').dialog('close');
$("input").val('');
}
else {
$.messager.alert("系統提示", "數據添加成功!");
return false;
}
}
})
}
encodeURIComponent編碼下你的內容,或者將內容放到data配置裡面,jquery會自動幫你編碼
url: "Handler.ashx?type=2&loginId=" +encodeURIComponent( loginid) + "&LoginPwd=" +encodeURIComponent( LoginPwd) + "&UserStateId=" + encodeURIComponent( UserStateId) + "&TeacherName=" + encodeURIComponent( TeacherName) + "&Sex=" + encodeURIComponent( Sex) + "&Birthday=" +encodeURIComponent( Birthday)
或者
url: "Handler.ashx',
data:{type:2,loginId:loginid.....................}