"sample1.php?q="+str
This code is for sending single parameter i need to send multiple variables
"sample1.php?q="+str
This code is for sending single parameter i need to send multiple variables
You can also create a url object for this and use the class methods:
const myURL = new URL('https://www.example.com');
myURL.searchParams.set('fooName', 'fooValue');
console.log(myURL);
// Output = https://www.example.com/?fooName='fooValue'
Define "multiple values". If you mean more than one variable, you can do something like:
$url = "sample1.php?q=".$str."&second=".$str2;
try this code:
<script>
function make_full_url(Page_URL,Params) {
Page_URL += "?";
for Key in Params
Page_URL += Key+"="+Params[Key]+"&";
return Page_URL;
}
//test
Page_URL = "sample1.php";
Params = new Array();
Params["q"] = Str;
Params["something"] = "something";
Full_URL = make_full_url(Page_URL,Params);
</script>
For HTML:
"sample1.php?q=" + str + "&otherParam=" + other;
For XHTML/XML:
"sample1.php?q=" + str + "%26otherParam=" + other;
i hope i understand you correct... make a array with your values and loop over the key values to concat your url string
$values = array('q' => $str, 'val2' => $val2);
$url = 'sample1.php';
$pos = 0;
foreach($values as $key => $value) {
$url .= ($pos>0 ? '&' : '?').$key.'='.urlencode($value);
$pos++;
}