PHP - Ajax调用不会在没有wait / print_r的情况下运行API [英] PHP - Ajax call won't run API without wait / print_r

查看:71
本文介绍了PHP - Ajax调用不会在没有wait / print_r的情况下运行API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过onClick事件与jQuery一起运行的脚本,我通过该函数传递一些信息。这是我的活动脚本。

I have a script that runs with jQuery via onClick event, I pass some information through that function. Here is my Event script.

$.post("page.php", { ... }, function(ret){ alert(ret); });

page.php 中,我调用API发送消息,页面完全是PHP,没有HTML。一切正常但消息不发送。但是,如果我直接从web运行相同的页面(没有ajax调用)运行和发送消息。

In page.php, I call an API for sending message, the page is completely PHP, no HTML is there. Everything works fine but message not send. But if i run the same page directly from web (without ajax call) run and send message.

page.php

$params = array(
    'str'  => $sms_content, // sms content
    'num'   => $cell_no,    // mobile number
);

$url = '.....api.php?'. http_build_query($params);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);


if (curl_errno($ch)){
    $result = curl_error($ch);
    $str = 'send message fail';
} else{
    $result = curl_exec($ch);
    $str = 'send message success';
}
echo $str;




注意:如果我添加< page.php 页面中的code> print_r()然后API发送消息。

Note: If i add an print_r() in the page.php page then the API send messages.

问题是什么,我该怎么办?

What is the problem, what can i do??

推荐答案

Ajax直接到api

Ajax directly to the api

    $params = {
        str:sms_content, // sms content
        num:cell_no    // mobile number
    };

  $.get("...api.php", { ... }, function(ret){ alert(ret); });

这篇关于PHP - Ajax调用不会在没有wait / print_r的情况下运行API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆