echo json_encode返回的json编码的字符串类型
post( url [, data ] [, success ] [, dataType ] )
-
-
urlType: StringA string containing the URL to which the request is sent.
-
dataType: PlainObject or StringA plain object or string that is sent to the server with the request.
-
successA callback function that is executed if the request succeeds. Required if
dataType
is provided, but can benull
in that case. -
dataTypeType: StringThe type of data expected from the server. Default: Intelligent Guess (xml, json, script, text, html).
-
-
所以需要
parseJSON( json )
去解析
Description: Takes a well-formed JSON string and returns the resulting JavaScript value.
parsejson是解析json格式的字符串
至于 tpp的ajaxreturn则直接返回的是json形式的数据而不是json一样的字符串
所以不需要parseJSON去解析
post知道它是json就会按照json格式处理
ajaxreturn的前端
$.post('/newinfo/index.php/Index/login',$(this).serialize(),function(data){
if(data.flag==0){
window.location.href='/newinfo/index.php/MainPage/index';
}else if(data.flag==1){
alert('E-mail address does not exist!');
}else{
alert('Email address and password do not match!');
}
},"json");
if(data.flag==0){
window.location.href='/newinfo/index.php/MainPage/index';
}else if(data.flag==1){
alert('E-mail address does not exist!');
}else{
alert('Email address and password do not match!');
}
},"json");
json_encode的前端
$.post('php/user_mgr.php',$(this).serialize(),function(data){
if($.parseJSON(data).flag==0){
window.location.href='ir_main.php';
}else if($.parseJSON(data).flag==1){
alert('E-mail address does not exist!');
}else{
alert('Email address and password do not match!');
}
});
if($.parseJSON(data).flag==0){
window.location.href='ir_main.php';
}else if($.parseJSON(data).flag==1){
alert('E-mail address does not exist!');
}else{
alert('Email address and password do not match!');
}
});