1

i have sorted xml file on the basis of item no.now i am trying to display data in javascript, but my code doesn't work, can anybody tell me what is wrong here

item.php:

         $xmlFile = "items.xml";
         $doc= DOMDocument::load($xmlFile);
         $item = $doc->getElementsByTagName("item"); 
         $items=array(); 
         foreach($item as $node) 
           {   
        $itemno = $node->getElementsByTagName("itemno");
        $itemno = $itemno->item(0)->nodeValue;
        $quantity = $node->getElementsByTagName("quantity");
        $quantity = $quantity->item(0)->nodeValue;
        $available = $node->getElementsByTagName("available");
        $available = $available->item(0)->nodeValue;
        $items[$itemno]= array($itemno,$quantity,$available);
           }

        ksort($items, SORT_NUMERIC); 
        foreach($item AS $ite => $no) 
         { 
           $itemnum=$no[0];
           $qty=$no[1];
           $avail=$no[2];
           echo $itemnum;  
           echo $qty;                 
           echo $avail;
         }

js:

var xhr = createRequest();
function getit( ) {
xhr.open("GET", 'item.php', true); 
xhr.onreadystatechange = getConfirm;  
xhr.send(null); 
}



function getConfirm()
{
if ((xhr.readyState == 4) &&(xhr.status == 200))   
   {
      var data = xhr.responseText;
      alert(data);                  
   }
}
1
  • I have retagged it to javascript, as it is related to it not to Java. Commented May 23, 2011 at 7:35

1 Answer 1

1

try xmlrequest in this flow in your javascript:

var xmlhttp;
    if (window.XMLHttpRequest)
     {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
     }
    else
     {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
     }
    xmlhttp.onreadystatechange=function()
     {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
         {
                document.getElementById("tbRow").innerHTML=xmlhttp.responseText;
                //lo();
         }
     }
    xmlhttp.open("GET","tbrow.php",true);
    xmlhttp.send();

Here "tbRow" is a "div" id. i.e.,

 <div id="tbRow"></div>
Sign up to request clarification or add additional context in comments.

2 Comments

but my code doesnt have any div tag, i want to display the php echo data through alert(); in javascript.
just create an empty div tag to store returned values.Then you can later use to show in alert box

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.