Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing multiple parameter to PHP from Javascript

Tags:

javascript

php

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); 
like image 444
NewDev Avatar asked Dec 16 '25 14:12

NewDev


1 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
like image 131
Andy E Avatar answered Dec 19 '25 09:12

Andy E



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!