jQuery Ajax Json回调问题

时间:2015-10-31 22:18:58

标签: php jquery json ajax jquery-callback

我正在研究移动应用程序,尝试通过jQuery Ajax将数据从应用程序发送到API。即使我定义了我的回调,它仍然给我一个回调错误。

下面的代码是连接到API的jQuery Ajax

function isDashboard(){
   var task = 'balance';
   var json = { // Create object
       "task" : task,
       "merchant" : getSession('x_u'), 
       "token" : getSession('x_token')
   };
   var jsonfull = []; // Push to jsonfull.
   jsonfull.push(json);
   var url = JSON.stringify(json);
   var crypt = CryptoJS.SHA512(getSession('x_token')+task+getSession('x_email')+url).toString(CryptoJS.enc.Hex);
   $.ajax({
       url: "http://samplesite.com/?p=app&'", 
       crossDomain: true,
       data: {
           json : url,
           hash :crypt
       },
       dataType: "jsonp"
   })
   .done(function (json){ 

       $('#welcome').prepend(json.response);
       alert(json.response);

   })
   .fail(function (jqxhr, textStatus, error){
       var err = textStatus + ", " + error;
       $('#welcome').prepend(err);

   });

}

在我的php文件中,我有

$rest = $_GET['json'];
$api = json_decode($rest,true);
$type = "json";
// did some processing with $api
//returning response to the app
$out = [];    
$out['response'] = 'X006';
$out['description'] = 'Invalid hash';
$out['values'] = '';
$out['salt'] = $salt;
$out['hash'] = '';
if($type == 'json'){
    header('Content-Type: text/json');
    $out = $_GET['callback'].'('.json_encode($out).')';
}
echo $out;      
die();

我一直收到错误parsererror,错误:jQuery1111036580699938349426_1446328908674未被调用

感谢我能得到的任何帮助。此致

0 个答案:

没有答案