1

I want to get data from submit.php page and put them in some tags in my page. in the example below I can put just on data in tag that has id: "shortcutTitle". I get more than one data from my php file(from database) and I want them to sit on various tags in my page.

function submit(shortcutid,shortcuttitle,shortcutlink,icon)
{
    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("shortcutTitle").value=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","submit.php?shid="+shortcutid+"&shtitle="+shortcuttitle+"&shlink="+shortcutlink+"&shicon="+icon,true);
    xmlhttp.send();
}
2
  • I'm afraid you question doesn't make much sense at the moment - you need to expand on the explanation of exactly what your are trying to achieve ... perhaps include your PHP to show what you are attempting to pass between PHP and JavaScript ? Commented Apr 18, 2012 at 9:41
  • what do you mean by "multiple data"? Commented Apr 18, 2012 at 9:42

1 Answer 1

3

You would want to use json_encode to send a javascript object back to the XML request

<?php
  echo json_encode( array('name' => 'tehlulz', 'id' => '1') );
?>

So from the results, you can then call the output by:

var ajaxResuts = {};

if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
  ajaxResuts = JSON.parse( xmlhttp.responseText );
  alert("Returned: " + ajaxResults.name);
}
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.