Patrik
Patrik

Reputation: 1327

Post XML data from jQuery to two PHP scripts

I'm sending XML data from jQuery by Ajax to first PHP script. It works fine.

jQuery - Ajax

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);

But then I need send this XML data from this first PHP script, to another second PHP script by cURL. But in the second PHP script XML data don't look the same. Html chats are changed.

How to solve this problem ?

Upvotes: 1

Views: 129

Answers (1)

Hassan ALi
Hassan ALi

Reputation: 1331

There are 4 parameters you have to specify: the url, dataType, success and type. The success function (xml) will hold the remaining code. The syntax is:

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

The HTTP request get will process the XML file. The url was the name of the list of cars, while the dataType is xml. In the success parameter, we’ve defined a function that executes when the file is successfully processed. The function (in out case) will loop through the XML code and read the file. We can also write code to print out an output, if necessary. Further here the complete tutorial ajax xml data

Upvotes: 1

Related Questions