本文介绍了PHP - Ajax调用不会在没有wait / print_r的情况下运行API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个通过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;问题是什么,我该怎么办?What is the problem, what can i do??推荐答案 Ajax直接到apiAjax 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-19 03:31
查看更多