Hello Experts,
I am developing application in which i use ajax.but i need to pass more than one variable to url for further processing. I can't use

var url="availabilitycheck.php?t="+value  //it works
var url="availabilitycheck.php?t="+value+"&hid="+hd1+"&chkin="+chkin; //not valid

How can i send other variables.??
I tried using session that works but it does not work when i integrated it to joomla.
So is there any way to pass more variable in url as querystring?

Recommended Answers

All 4 Replies

Chintan,

Your code should work providing value , hd1 and chkin exist. Otherwise javascript will generate an error.

I generally build search strings like this in an array, then use Array.join() to put the pieces together.

var searchString = [];
searchString.push("t=" + value);
searchString.push("hid=" + hd1);
searchString.push("chkin=" + chkin);
var url = "availabilitycheck.php" + searchString.join('&');

By doing it this way, you get a more informative line number should a javascript error arise.

Airshow

Try this

var url=("availabilitycheck.php?t="+value+"&hid="+hd1+"&chkin="+chkin);

Just noticed a missing ? in my post above

Line 5 hould be

var url = "availabilitycheck.php?" + searchString.join('&');

Airshow

As Airshow said, if value of any of your variable t, hd1 and chkin does not exist, it will break your JavaScript. If you have Firefox, you should install firebug to aid you in debugging (firebug will show you where the error occurs and from what possible reason). If you use IE, there will be a small yellow icon with exclamation at the bottom left if there is any error in your script. You need to double click on that icon to see somewhat not useful information of the error... But at least you know that there is an error...

If you know and may not expect to see some variables on the server side (and have a mechanism to validate and handle on your server side), you could add something like...

// modified from Airshow's code
var searchString = [];
if(!isNaN(value) || value) { searchString.push("t=" + value); }
if(!isNaN(hd1) || hd1) { searchString.push("hid=" + hd1); }
if(!isNaN(chkin) || chkin) { searchString.push("chkin=" + chkin); }
var url = "availabilitycheck.php?" + searchString.join('&');
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.