2016-07-22 44 views
1

我將Ajax中的XML數據從Ajax發送到第一個PHP腳本。它工作正常。將XML數據從jQuery發佈到兩個PHP腳本

jQuery的 - 阿賈克斯

open('POST', 'get_and_send_XML.php', { xml: newXmlString1 }, '_blank'); 

get_and_send_XML.php

$data = $_POST['xml']; 
$fh = fopen('first.txt', 'w') or die("Can't create file"); 
fwrite($fh, $data); 
fclose($fh); 

curl_setopt($ch, CURLOPT_URL,"http://domain.com/second.php"); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, "xml=". $data); 

second.php

$data = $_POST['xml']; 
$fh = fopen('second.txt', 'w') or die("Can't create file"); 
fwrite($fh, $data); 
fclose($fh); 

但後來我需要從這個第一PHP腳本發送XML數據,另一第二PHP腳本由cURL。但在第二個PHP腳本中,XML數據看起來不一樣。 Html聊天改變了。

如何解決這個問題?

+0

你應該給我們多一點信息,至少兩個PHP腳本 –

+0

內容請把你的代碼,這將有助於得到最佳的答案 – Sachith

+0

呀,我們對此深感抱歉。我編輯了原文。 ;-) – Patrik

回答

1

您必須指定4個參數:url,dataType,success和type。成功函數(xml)將包含剩餘的代碼。語法是:

$.ajax({ 
type: "GET", 
url: "cars.xml", 
dataType: "xml", 
success: function(xml) { 
} 
//other code 
error: function() { 
alert("The XML File could not be processed correctly."); 
} 
}); 

HTTP請求get將處理XML文件。 url是汽車列表的名稱,而dataType是xml。在成功參數中,我們定義了一個在成功處理文件時執行的函數。該函數(在外殼中)將遍歷XML代碼並讀取該文件。如有必要,我們還可以編寫代碼打印輸出。 而且這裏的完整的教程ajax xml data

+0

我編輯了原文。 – Patrik

相關問題