使用SOAP-php发送API请求时AJAX响应0

时间:2015-03-10 14:48:51

标签: php jquery ajax wordpress soap

jQuery的:

jQuery.ajax
        ({
            url:    ajaxurl,
            type:   'POST',
            data:   {
                        action: 'shipping_data',
            },
             processData: false, 

            success: function(data)
            {
                alert(data);
            },
            error: function(data)
            {
                alert("failed.");
            }
        });

PHP:

function shipping_data()
{
// Testing for now. 
 $requestParams = array(
    'CityName' => 'Berlin',
    'CountryName' => 'Germany'
);

$client = new SoapClient('http://www.webservicex.net/globalweather.asmx?WSDL');
echo  $response = $client->GetWeather($requestParams);
die();

}
add_action( 'wp_ajax_shipping_data', 'shipping_data' );
add_action( 'wp_ajax_nopriv_shipping_data', 'shipping_data' ); 

我使用processData: false,并获得响应0.在我收到失败的回复之前。为什么我无法收到请求?如果我在shipping_data函数之外使用SOAP,那么我可以获得响应。但我想在shipping_data函数(使用ajax调用)内部使用任何帮助吗?

1 个答案:

答案 0 :(得分:0)

0是ajax的默认错误代码,无论你做什么都是硬编码错误。 大多数时候你使用die();它将打破一切,尝试用

替换它
exit;