以下是我的js:
<script type="text/javascript">
function checkNameExist(obj,obj2,async) {
if (typeof(async) == "undefined") async = true;
var m = $.trim(obj.val());
var n = $.trim(obj2.val());
m =encodeURI(m);
n =encodeURI(n);
var b = false;
$.ajax({
type: "GET",
async: async,
url: "/ajax/member/isNameExist/" + m + "/"+ n + "/" + Math.random(),
dataType: "script",
success: function(data) {
if(data == 1) {
$("#"+obj.attr("name")).text('匹配成功!').css("color", "#000000");
b = true;
} else {
$("#"+obj.attr("name")).text('对不起,帐户和姓名不匹配!').css("color", "#ff0000");
$("input[name='name']").focus();
b = false;
}
}
});
return b ;
}
</script>
下面是member文件的函数(在MVC模式下,仅供参考)
function isNameExist($name = '',$username = '') {
$this->load->database();
$name=urldecode($name);
$username=urldecode($username);
if (trim($username) != '') {
$query = $this->db->get_where('members', array('username' => $username,'chinese_name' => $name));
echo $query->num_rows(); //如果成立,则输出1,
} else {
return 'error';
}
}
原来是url地址里面有非法字符,
http://hx0000/ajax/member/isNumberExist/%E4%BD%A0%E5%A5%BD/
看来MVC模式下地址里面不能有%符号!
能不能依我的例子写一个用 POST 传参的例子?