I have a php file (myxml.php) that uses a 3rd-party API to return XML. It echoes the XML on the last line.
$xml = file_get_contents($url);
echo $xml;
Another php file (index.php) uses jQuery to read this XML in:
$(document).ready(function(){
$.ajax({
type: "GET",
url: "myxml.php",
dataType: "xml",
success: function(xml) {
My index.php file needs to pass the myxml.php file a variable called ‘searchitem’ that it can use before calling the API.
How do I pass $searchitem to myxml.php ?
Also, for better performance, can I import the php variable $xml to my ajax code above without the need to echo it?
Thanks in advance
You apparently are using jQuery.
Just add it to the url (so build the jQuery syntax with php)
In turn, on myxml.php you can get this with the
$_GETvariable.Without echo? Only possible if you don’t need ajax, so you can just include the myxml.php file into the index.php file. But I assume there is a good reason for doing ajax