PDA

View Full Version : XMLHTTP.OPEN format to sent variables GET


soneen
06-24-2010, 08:44 PM
I'm having some trouble sending variables through a URL, javascript style. I'm pretty sure the problem lies in the syntax of my url. Quick help?

function showMorePosts(str,sort)
{
xmlhttp.open('GET','ajaxQueries.php?sort=+sort&q=+str,true');
}

soneen
06-24-2010, 10:29 PM
FIXED:


xmlhttp.open('GET','ajaxQueries.php?sort='+sortBy+'&q='+str,true);

soneen
06-25-2010, 12:14 AM
Alright talking to myself here. One more problem. Whenever this function sorts itself out, the value of the variable I want ends up "undefined".

It starts here in my code with this link. $sort is the variable that's giving me trouble. If I echo it here, it works correctly.
<a id='showMoreLink' onclick='showMorePosts($showMoreCount,$sort)'>Show more...</a>

Here is snippets of the showMorePosts function
function showMorePosts(str,sortBy)
{
xmlhttp.open('GET','ajaxQueries.php?sort='+sortBy+'&q='+str,true);
xmlhttp.send();
}


And here is where I am echoing $sort in ajaxQueries.php, and getting "undefined". Note that $q works just as it should. (All I can think is q is an integer, and sort is a string)

$q=$_GET['q'];
$sort=$_GET['sort'];

echo $sort.$q;

Dormilich
06-25-2010, 11:16 AM
I suppose $sort is a string, then you have to tell JavaScript that:
<a id='showMoreLink' onclick='showMorePosts($showMoreCount, \"$sort\")'>Show more...</a>

soneen
06-25-2010, 03:55 PM
RESOLVED. Thank you!