doushen2154 2012-10-18 17:02
浏览 55

PHP / Curl / Wordpress在没有刷新页面的情况下发布数据,卷曲不起作用

I am writing code for a donation page and want to submit CC information without refreshing the page, and display the results using an overlay. I have the overlay working correctly using jQuery, and using a php if statement, I can post back to the page I am on and get the variables correctly the the curl block for the CC transaction. However I never get any results. If I allow the page to POST/refresh it works fine, but it seems Wordpress will not allow me to run the curl from a page that is not directly run in the enviroment.

Any suggestions?

jQuery.post('sameurl', jQuery("#donateform").serialize(), function(data) {
  jQuery('#overlay_msg').html(data);

and

        $ch = curl_init ();

        curl_setopt ($ch, CURLOPT_URL,$hoststring);
        curl_setopt ($ch, CURLOPT_POST, 1); 
        curl_setopt ($ch, CURLOPT_POSTFIELDS, $xml); # the string we built above
        curl_setopt ($ch, CURLOPT_SSLCERT, $cert);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt ($ch, CURLOPT_VERBOSE, 1);

        $result = curl_exec ($ch);

I hard coded the $xml string as well trying to get it to work. I'm new to php/curl/ajax but know a bit about coding in general.

Thanks.

  • 写回答

2条回答 默认 最新

  • duandeng2011 2012-10-23 13:43
    关注

    From what I can see your code is not calling any wordpress functions, so there is no dependency there. It sounds like the cURL call is not completing successfully, you will need to debug this. Make sure php error reporting is on and set to E_All in your php.ini, also set the curl option FAILONERROR to true and be sure to catch any errors using the curl error functions.

    Failing this you may need to analyse the HTTP headers to see whats being received from the server. You may simply be getting a redirect try setting CURLOPT_FOLLOWLOCATION to true.

    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大