Implement PHP Curl invoke methods in different projects

Source: Internet
Author: User

Some of the problems and workarounds that were encountered in order to implement cross-project invocation methods are summarized.

Not much to say, the direct copy of the code to run the first word!

JQ code.

$.ajax ({
Type: "Post",

DataType: "JSON",
URL: "",
Data:null,
Success:function (Result) {

Console.log (result);

},
Error:function () {

}
});

PHP code

$host = "Http://xxxxxx/index.php/Home/index/index";
$ch = Curl_init ($host);
curl_setopt ($ch, Curlopt_header, 0);
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, curlopt_timeout,5);
$arra = curl_exec ($ch);
Var_dump ($arra);

$arra = Json_decode ($arra, true);
$arra = Json_decode (substr ($arra, 3), true); Before using Teamview connected to another computer with a disgusting windows self-brought TXT opened the project file (spit ... hehe). The data will be lost directly afterwards. Normal direct use of Json_decode ($arr) can be

Working with Data

foreach ($recommend as $value) {
$RMD [] = Array_merge ($value, [' PageView ' =>0]);
}
foreach ($rmd as & $value) {
foreach ($arra as $v) {
if ($value [' id '] = = $v [' shop_id ']) {
$value [' pageview '] = $v [' PageView '];
}
}
}

Spit out the data can

PHP Interface Code

Public Function Index ()
{
$arr = Array (' data data ');
Exit (Json_encode ($arr));
}

Run a bit. Well?????  Why the backend request to the data, the front end has no data ... wtf

Kiss! Don't worry, first think about what the reason is.

Methods are not found through various methods ...

All right. Link Answer: https://segmentfault.com/q/1010000015934974

Implement PHP Curl invoke methods in different projects

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.