1

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 ?

3
  • You should give us little bit more information, at least the contents of both php scripts Commented Jul 22, 2016 at 14:13
  • please post your code, it will help to give the best answer Commented Jul 22, 2016 at 14:19
  • Yeah, Sorry about that. I edited original post. ;-) Commented Jul 22, 2016 at 14:22

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.