PHP responds to JSONP operations.
I do cross domain use to Vue-resource, this Baidu can download:
Here is the HTML page Ajax:
Plus v-model= "", the JS method will check the value of the inside
<script src= "Js/lib/jquery.js" type= "Text/javascript" charset= "Utf-8" ></script>
<script src= "Js/lib/vue.js" type= "Text/javascript" charset= "Utf-8" ></script>
<script src= "Js/lib/vue-resource.js" type= "Text/javascript" charset= "Utf-8" ></script>
<input class= "Name-input" type= "text" name= "value=" "v-model=" name "/>
<input class= "password-input" type= "password" "Name=" "value=" v-model= "password"
<span class= "login-btn" @click = "Add ()" > Login </span>
<script>
var vm = new Vue ({
EL: ". Main",
Data: {
Name: "",
Password: ""
},
Methods: {
Add:function () {
this. $http. Jsonp ("Domain/login"
, {
Name:this.name,
Pass:this.password
}
). Then (function (res) {
if (Res.data.type = = "1") {
Window.location.href = "cg.html";
} else {
Alert ("Account password Error")
}
}, function (res) {
Alert ("Verify failure Please login again")
});
}
}
})
</script>
Public Function login () {
$callback = $_get[' callback ']; This is important.
$name = $_get[' name '];
$pass = $_get[' Pass '];
if ($name = = ' 123456 ' and $pass = = ' 123456 ') {
$json = Array (' type ' =>1, ' name ' => $name, ' Pass ' => $pass); Logon value Error
} else {
$json = Array (' type ' =>0, ' name ' => $name, ' Pass ' => $pass); Login value is correct
}
$date = Json_encode ($json);
echo $callback. " ($date) ";
}
After the success of the jump to the cg.html page;