HTML5 client cross-domain access to PHP service-side data

Source: Internet
Author: User

Client code:

var param = $.param (
{
Feed:JSON.stringify ({
Content: ' ABCD '
})
}
);

$http ({
URL: ' http://61.153.100.80/pay/talent.php ',
Method: "POST",
Data:param,
Headers: {' content-type ': ' application/x-www-form-urlencoded '}
}). Success (function (data, status, headers, config) {
$ (' #dvTalent '). HTML (data.talent);
}). Error (Function (data, status, headers, config) {

});


$.ajax ({
Type: ' Post ',
URL: ' http://61.153.100.80/pay/talent.php ',//i has the actual URL here's course
Cache:false,
ContentType: ' application/x-www-form-urlencoded ',
Crossdomain:true,
Success:function (data) {
alert (data.talent);
Doing stuff with data on here
}, Error:function (JQXHR, Textstatus, Errorthrown) {
Alert (' Critical error. Everything is exploding. Abort mission. ');
}
});

PHP service-side code returned {"Talent": 32}

<?php
error_reporting (0);
Header (' access-control-allow-origin:* ');
Header (' access-control-allow-headers:authorization ');
Header (' Content-type:application/json; Charset=utf-8 ');
Header (' access-control-allow-methods:put,post,get,delete,options ');

echo json_encode (Array (' talent ' =>132));

HTML5 client cross-domain access to PHP service-side data

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.