-1

I have 2 PHP Variables: $category1 and $category2

I want the URL to be like this:

?category1=$category1&category2=$category2&q=str

I only know PHP, I have very less knowledge of JS/Jquery, can someone help me in this small thing?

I tried this:

var category1 = '<?php echo $category1; ?>';
var category2 = '<?php echo $category2; ?>';

But, idk what to write here

xmlhttp.open("GET","getuser.php?q="+str,true);
Rahul Sharma
  • 47
  • 1
  • 5
  • so the only issue is string concatenation in javascript? –  Jun 22 '17 at 05:29
  • Possible duplicate of [Best way to concatenate strings in JavaScript?](https://stackoverflow.com/questions/16696632/best-way-to-concatenate-strings-in-javascript) –  Jun 22 '17 at 05:30
  • Yeah probably.. – Rahul Sharma Jun 22 '17 at 05:35
  • @rtfm i do not understand anything in that question. Bcz i have less knowledge of JS. This is very small thing, it can be answered in 30 sec :/ – Rahul Sharma Jun 22 '17 at 05:36

3 Answers3

0

Try this

xmlhttp.open("GET","getuser.php?q="+ str +"&category1="+ category1 +"&category2=" +category2+,true);
Arun Kumaresh
  • 6,211
  • 6
  • 32
  • 50
0
var category1 = '<?php echo $category1; ?>';
var category2 = '<?php echo $category2; ?>';
var url = "category1="+category1+"&category2="+category2+"&q=str";
xmlhttp.open("GET","getuser.php?"+url,true);

You will get your url just like you mentioned

Vinit Chouhan
  • 686
  • 1
  • 10
  • 23
0

Try:

xmlhttp.open("GET","getuser.php?q=" + str + "&category1=" + category1 + "&category2=" + category2,true);

Use + to concat the string

Versha Gupta
  • 265
  • 2
  • 3
  • 10