JSONP cross domain request, Vue-resource + PHP back and forth end split do webapp__c#

Source: Internet
Author: User

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.