2015-04-07 73 views
1

我有一個jQuery的Ajax POST請求去一個PHP網站與一些數據添加在_POST數組。 我無法弄清楚爲什麼在Ajax響應中,我好像在我的JSON響應之前將_POST數組返回給我。我想要的只是下面回覆中的第二行。爲什麼我的jQuery Ajax響應首先包含post數組?

$.ajax({ 
type: "POST", 
url: "site.php", 
data: { requestType : 'someType', table : 'someTable' }, 
success: function(data){ 
    alert(data); 
}, 
error: function(XMLHttpRequest, textStatus, errorThrown) { 
    alert(errorThrown); //or whatever 
} 
}); 

響應:

array(2) { ["requestType"]=> string(6) "someType" ["table"]=> string(17) "someTable" } 
[{"User":1,"User":"xxx","Pd":"xxx","Name":"xxx","Age":xx,"Occupation":"xxx","Description":"xxx"}] 

的PHP

$result = $stmt->execute(); 

//put the results in to the $result variable 
$result = $stmt->get_result(); 

while ($row = $result->fetch_assoc()) {      
    array_push($result_array, $row); 
} 

echo json_encode($result_array); 
+0

mmmmm看看你打印出來的文件是什麼,因爲這不是JQuery的東西。 – BlaShadow

+1

向我們展示您的php代碼。你如何回覆回覆? – Arlind

回答

-1

嘗試更改此代碼: success: function(data){ alert(data); }

success: function(response){ alert(response); }

請記住,清除緩存。

0

使用下面的代碼來填充變量$item$row變量的值。

while ($row = $result->fetch_assoc()) {  
     $item['Pd'] = $row['Pd']; 
     $item['Name'] = $row['Name'];    
     array_push($result_array, $item); 
    } 
相關問題