sms 알림을 보내기 위해 wordpress 플러그인을 수정하기 위해 다른 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();
?>
이것이 다른 도움이되기를 바랍니다. :)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다