另一个http请求中的http请求成功响应在jquery中不工作

另一个http请求中的http请求成功响应在jquery中不工作,jquery,wordpress,Jquery,Wordpress,为了修改wordpress插件以发送sms通知,我尝试在另一个http请求的成功响应内使用jquery.post()事件发出http请求,但第二个http请求不工作,它不会返回任何响应,我的代码有什么问题 //first http request jQuery.post(redi_restaurant_reservation.ajaxurl, data, function (response) { jQuery('#redi-restaurant-step3').attr('disab

为了修改wordpress插件以发送sms通知,我尝试在另一个http请求的成功响应内使用jquery.post()事件发出http请求,但第二个http请求不工作,它不会返回任何响应,我的代码有什么问题

//first http request

jQuery.post(redi_restaurant_reservation.ajaxurl, data, function (response) {
    jQuery('#redi-restaurant-step3').attr('disabled', false);
    jQuery('#step3load').hide();
    if (response['Error']) {
        jQuery('#step3errors').html(response['Error']).show('slow');
    } else {
        var smsurl = 'http://sms.mysitename.com/SendSms.aspx?uid=myuserId&pass=123&contact=phone&sms=smstext&rnd=randomnumber';
        alert(smsurl);
        //

        //2nd http request. problem arises from here............

        jQuery.post(smsurl, function (a) {

        alert('hello'); //not show any alert here

        if (a['Error']) { 
            alert('if');
            jQuery('#step3errors').html(a['Error']).show('slow');
        } else {

            alert('successfully sent');
        } 
         }, 'json');

        ga_event('Reservation confirmed', '');
        jQuery('#step1').hide('slow');
        jQuery('#step2').hide('slow');
        jQuery('#step3').hide('slow');
        jQuery('#step4').show('slow'); //success message
        jQuery('html, body').animate({scrollTop: 0}, 'slow');
    }
}, 'json');

就我而言,所有的麻烦都属于这一行-

 var smsurl = 'http://sms.mysitename.com/SendSms.aspx?uid=myuserId&pass=123&contact=phone&sms=smstext&rnd=randomnumber';
jQuery.post()事件无法直接使用此url

因此,我修改了我的代码如下,它的工作方式就像魅力

                var msg = encodeURIComponent("Your reservation is confirmed! Thank you for your reservation");
                var smsurl = "http://sms.mysitename.com/SendSms.aspx?uid=myuserId&pass=123&contact="+userPhone+"&sms="+msg+"&rnd=123";
                var data = {url: smsurl};

                jQuery.post('http://localhost/booking/wp-admin/sendsms.php', data, function (response) {

                    if (response['Error']) {
                    jQuery('#step3errors').html(response['Error']).show('slow');
                    } else {
                        ga_event('Reservation confirmed', '');
                        jQuery('#step1').hide('slow');
                        jQuery('#step2').hide('slow');
                        jQuery('#step3').hide('slow');
                        jQuery('#step4').show('slow'); //success message
                        jQuery('html, body').animate({scrollTop: 0}, 'slow');
                    }

                });
我的sendsms.php执行CURL请求并返回我想要的响应

<?php
$ch = curl_init();
$the_url = $_POST['url'];
curl_setopt($ch, CURLOPT_URL, $the_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
$result = curl_exec($ch);
curl_close($ch);
echo $result; //die();
?>


希望这对其他人有帮助。:)

就我而言,所有的麻烦都属于这一行-

 var smsurl = 'http://sms.mysitename.com/SendSms.aspx?uid=myuserId&pass=123&contact=phone&sms=smstext&rnd=randomnumber';
jQuery.post()事件无法直接使用此url

因此,我修改了我的代码如下,它的工作方式就像魅力

                var msg = encodeURIComponent("Your reservation is confirmed! Thank you for your reservation");
                var smsurl = "http://sms.mysitename.com/SendSms.aspx?uid=myuserId&pass=123&contact="+userPhone+"&sms="+msg+"&rnd=123";
                var data = {url: smsurl};

                jQuery.post('http://localhost/booking/wp-admin/sendsms.php', data, function (response) {

                    if (response['Error']) {
                    jQuery('#step3errors').html(response['Error']).show('slow');
                    } else {
                        ga_event('Reservation confirmed', '');
                        jQuery('#step1').hide('slow');
                        jQuery('#step2').hide('slow');
                        jQuery('#step3').hide('slow');
                        jQuery('#step4').show('slow'); //success message
                        jQuery('html, body').animate({scrollTop: 0}, 'slow');
                    }

                });
我的sendsms.php执行CURL请求并返回我想要的响应

<?php
$ch = curl_init();
$the_url = $_POST['url'];
curl_setopt($ch, CURLOPT_URL, $the_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
$result = curl_exec($ch);
curl_close($ch);
echo $result; //die();
?>


希望这对其他人有帮助。:)

代码没有问题,exept POST仅适用于同一域

代码没有问题,exept POST仅适用于同一域