Wrap text
Report abuse
|
|
/*
这里以jQuery的Ajax实现为例
引用、调用提交事件 这里略...
*/
/**
* 注册页面JS类库
*/
var Signup = {
/**
* Ajax提交事件
*/
post : function(){
// 读DOM的值略...
$.ajax({
url : "/signup",
data: "username=" + username + "&password=" + password,
dataType: "json",
type : "post",
success : function(state){
/*
在JS里面接收state,jQuery的AJAX会自动将它用JSON反序列化成对象
于是我们就可以像在Python里面一样使用了 如 state.message
*/
if(! state.success){
# 错误处理
alert(state.message);
}
else{
alert("注册成功。");
location.href = "/success.html";
}
}
})
}
}
|