1

i want to send two variables values from one file, which have XML code where i have function which include the php file, so i want it should include this php file with my passed values, am doing like following way


function load(){
    var id=cn;
    var name="zuni";

    downloadUrl('info.php?id2=id&name2=name', function(data) {

    });

code in info.php

if (isset($_GET['id'])) {
    $id2 = $_GET['id2'];
    $name2 = $_GET['name2']; 
    echo "id is :". $id2;
    echo "name is :". $name2; 
}   

its output is showing like this


id is:id
name is: name

its not displaying variable value but variable name, i want its value not name any one can check whats wrong with this code ?

4
  • What? In id2=id&name2=name value of id2 is id, same to name2. And scripts outputs just what you've passed to it. Commented Jun 11, 2017 at 9:51
  • @u_mulder i want to to pass value of name2="zuni" not name2=name Commented Jun 11, 2017 at 9:53
  • See the answer. Commented Jun 11, 2017 at 9:54
  • See the answer. Commented Jun 11, 2017 at 9:54

2 Answers 2

2

This is happening because the request URL that you are passing have literal values

  'info.php?id2=id&name2=name'.

To solve the problem you have to use the code below instead:

  "info.php?id2=" + id + "&name2=" + name
Sign up to request clarification or add additional context in comments.

1 Comment

@mjunaid It is always my pleasure to give back to the community ;)
0

if you want your code to work you shoud use back tick to inject your variable in your download request :

downloadUrl(`info.php?id2=${id}&name2=${name}`, function(data) {

or use the string concatenation

downloadUrl('info.php?id2=' + id + '&name2=' + name, function(data) {

you actually pass id and name to your GET resquest. This is normal that your server get id and name.

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.