GET和POST,ajax问题遗留
<!DOCTYPE html>
<
html
lang=
"en"
>
< head >
< meta charset= "UTF-8" >
< title >getPostDemo </ title >
< script type= "text/javascript" src= "jquary/jquery-3.0.0.min.js" ></ script >
</ head >
< body >
< input type= "button" οnclick= " postMessage() " value= "点击我" />
< script type= "text/javascript" >
function postMessage(){
$. ajax({
type: "post",
url: "getPostDemoTest.php",
data:{
"code": 100,
"user": "admin"
},
success: function(data){
var result = eval( "("+data+ ")");
console. log( result. code);
console. log(data);
}
});
}
</ script >
</ body >
< head >
< meta charset= "UTF-8" >
< title >getPostDemo </ title >
< script type= "text/javascript" src= "jquary/jquery-3.0.0.min.js" ></ script >
</ head >
< body >
< input type= "button" οnclick= " postMessage() " value= "点击我" />
< script type= "text/javascript" >
function postMessage(){
$. ajax({
type: "post",
url: "getPostDemoTest.php",
data:{
"code": 100,
"user": "admin"
},
success: function(data){
var result = eval( "("+data+ ")");
console. log( result. code);
console. log(data);
}
});
}
</ script >
</ body >
</html>
<?php
/**
/**
* Created by PhpStorm.
* User: liugaoyang
* Date: 2016/7/15
* Time: 11:39
*/
//当客户端发送数据时。服务器返回数据
if ( $_POST [ "code" ]== 100 ){
$arr = array ( "code" => 100 , "user" => "admin" );
echo json_encode( $arr );
} else {
echo json_encode( array ( "code" => "youcuowu" ));
* Time: 11:39
*/
//当客户端发送数据时。服务器返回数据
if ( $_POST [ "code" ]== 100 ){
$arr = array ( "code" => 100 , "user" => "admin" );
echo json_encode( $arr );
} else {
echo json_encode( array ( "code" => "youcuowu" ));
}
2.
<!DOCTYPE
html
>
< html lang= "en" >
< head >
< meta charset= "UTF-8" >
< title >getPostDemo </ title >
< script type= "text/javascript" src= "jquary/jquery-3.0.0.min.js" ></ script >
</ head >
< body >
< input type= "button" οnclick= " postMessage() " value= "点击我" />
< script type= "text/javascript" >
// post只可以在data里面传参,如果在url里面传参默认为是get.
function postMessage(){
$. ajax({
type: "post",
url: "getPostDemo.php",
data:{
"code": 11
},
success: function(data){
alert(data);
}
});
}
</ script >
</ body >
< html lang= "en" >
< head >
< meta charset= "UTF-8" >
< title >getPostDemo </ title >
< script type= "text/javascript" src= "jquary/jquery-3.0.0.min.js" ></ script >
</ head >
< body >
< input type= "button" οnclick= " postMessage() " value= "点击我" />
< script type= "text/javascript" >
// post只可以在data里面传参,如果在url里面传参默认为是get.
function postMessage(){
$. ajax({
type: "post",
url: "getPostDemo.php",
data:{
"code": 11
},
success: function(data){
alert(data);
}
});
}
</ script >
</ body >
</html>
echo
"get"
;
//print_r($_GET);
echo json_encode( $_GET );
echo "post" ;
//print_r($_POST);
echo json_encode( $_POST );
//print_r($_GET);
echo json_encode( $_GET );
echo "post" ;
//print_r($_POST);
echo json_encode( $_POST );