Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i am trying to Use this

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;
}

function CallSomePHP()
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
    alert ("Browser does not support HTTP Request");
    return;
    }
    var url="myPhp.php"; ***(Need to Pass multiple parameter to php from here)***
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

function stateChanged()
{
    if (xmlhttp.readyState==4)
    {
        alert(xmlhttp.responseText);
share|improve this question
 
You can post code using code blocks to lay it out much neater with lines and spacing. It's the button that looks like binary code 101010 just above the edit box. (alternatively, insert 4 spaces before each line of code) –  Andy E Oct 21 '09 at 11:57
add comment

2 Answers

You add them to the URL string, so:

var url="myPhp.php?a=1&b=2&c=3";

then you can access them in PHP from the $_GET array:

$Param1 = $_GET['a']; // = 1
$Param2 = $_GET['b']; // = 2
$Param3 = $_GET['c']; // = 3
share|improve this answer
add comment

This is really easy:

var url="myPhp.php?param1="+ param1 + "&param2=" + param2

However you might consider using jQuery.

As it would become even easier ;)

To have a complete ajax call you need only one method call without having to care about browser issues. So your code becomes a lot easier to read.

 $.ajax({
   // you can use post and get:
   type: "POST",
   // your url
   url: "some.php",
   // your arguments
   data: {name : "John", location : "Boston"},
   // callback for a server message:
   success: function( msg ){
     alert( "Data Saved: " + msg );
   },
   // callback for a server error message or a ajax error
   error: function( msg )
   {
     alert( "Data was not saved: " + msg );
   }
 });
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.