Jquery Ajax不在服务器上工作但在localhost上工作

时间:2016-08-31 00:49:33

标签: javascript php jquery ajax

我有以下jquery代码将数据发布到php文件并在localhost上正常工作。但是当此代码现在在服务器上时,脚本会返回错误而不是数据。

  $.ajax({
        type: 'POST',
        url: 'scripts/info.php',
        data: {

            accountNumber: accountNumber,
            agentName: name

        },
        success: function( data ) {
            alert(data)
        },
        error: function(xhr, status, error) {
            // check status && error
            alert(status)
        }
    });

这是处理帖子请求的php文件中的代码:

$args0 = array(
'accountNumber' => $_POST['accountNumber'],
'dateReceived' => date("Y-m-d"),
'firstNames' => $_POST['agentName']    '
'regNumber' => $_POST['accountNumber'],
'surname' => $_POST['agentName']
);

try {
$client = new SoapClient(WSDL_URL, array(
    'trace' => 1,
    'exceptions' => true,
    'connection_timeout' => 300));

$params = array(
    'arg0' => $args0,

);


$client->__setLocation(WSDL_LOCATION);
$response = $client->upload($params);
$response = $client->__getLastResponse();

echo $response;

请帮忙

1 个答案:

答案 0 :(得分:0)

$.ajax({
    type:"post",
    url:"/pay/index.php?submit_order=yes",
    dataType:'json',
    data:{
        'rmb': $('#rmb').val(),
        'couponid': $('#cid').val(),
        'title' :$('#title').text(),
        'user' :$('#user').text(),
        'phone' :$('#phone').text(),
        'code' :$('#code').text(),
        'size' :$('#size').text(),
        'isinvoice':$('[name=isinvoice]').val()
    },
    beforeSend:function(){
        beforeSend.attr('disabled',true);
        beforeSend.html('submitting').removeAttr('href');
    },
    success:function(data){
        if(data.errorcode==1){
            $('.pay-fail').show().text(data.message);
        }else{
            if(data.url){
                location.href=data.url;
            }else{
                alert('post ok!');
            }
        }                      
    },
    error: function(){
        alert('submit error,then try again');
    }
})

这是我的jQuery ajax for pay。它适用于localhost和服务器。

相关问题