Jump to content

place an ajax returned responseXML element into a php variable


davey10101

Recommended Posts

Hey guys, complete noob here hope someone can help.

I have an ajax responseXML file that returns a series of mysql query values as elements to a span id in my php file.

What I want to do is aswell as display this returned value, also place it into a php variable so i can use it again either in the same php file or in another like so..

var xmlhttp;

function showUser(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="responseXML.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
//xmlhttp.overrideMimeType('text/xml');
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
  {

  xmlDoc=xmlhttp.responseXML;  
  document.getElementById("Groupid").innerHTML=
  xmlDoc.getElementsByTagName("groupiD")[0].childNodes[0].nodeValue; 

}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}


 

I print the result in a table but want to 'capture' it also..

 

<tr>
     <th align="left">Group ID</th>
<td><span id="Groupid"></span></td>
<?php $thisID="'<span id="Groupid"></span>'";
?>
</tr>

 

 

can anyone help?

 

Many Thanks

Link to comment
Share on other sites

I dont think you can put an AJAX - XML responce into a PHP varible.

 

You can put an AJAX - XML responce into the current page your using, which i think thats what you want anyways.

 

Is the problem your having have to do with the group_id?

Really if i had to guess your having trouble outputting the XML data into the fields you want.

 

            // News XML Section transfer to ADD news table // 

            var news_ = xml_ajax_control.getElementsByTagName("group_id");

            for (i=0; i<(news_.length); i++){

                var news_add_1 = news_.getElementsByTagName("name")[0].firstChild.nodeValue;

                var news_add_2 = news_.getElementsByTagName("date")[0].firstChild.nodeValue;

                var news_add_3 = news_.getElementsByTagName("type")[0].firstChild.nodeValue;

 

// ignore the next line of code, thats for adding rows to a table the above is getting XML data and space it out into varibles, then you can output the varible data into something like the function below and that function handles how the data is outputted and where.  Also while outputting the data you can format the data with inline CSS and make javascript functions with inline javascript.  If you dont understand what i mean by inline CSS/javascript dont bother yourself with it, if you do understand have fun.

            news_update_addRow(news_add_1,news_add_2,news_add_3);}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.