Forum Moderators: open
Here's my function:
function ajaxplz(pageLoad, divId) {
var pager = pageLoad.split("?");
var page = pager[0];
var gets = pager[1].split("&");
var variables = new Array();
for (var i=0;i<gets.length;i++)
{
var get = gets[i].split("=")
variables[i] = get[0]+":\""+get[1]+"\"";
}
variables.join(", ");
variables = "{ "+variables+" }";
$(function(){
$("#"+divId)
.html("<img src='loading.gif' id='loading'>")
$.get(page, eval(variables),
function(data) {
$("#"+divId).html(data)
$("#loading").remove()
});
});
}
<a onclick='ajaxplz("page.php?variable1=value&variable2=value","result")'>Click here!</a>
As you can see, I'm parsing out the get variables from the PHP url and loading them into a string. That's no problem! The problem is that the string when completed looks like this (which is perfect in every way):
{ variable1: value, variable2: value }
But javascript says "variable2" is an invalid label? What's going on? I have tried adding parentheses inside the eval statement, which I saw as a solution to some JSON problems.
I'm kinda noob with jquery and this is confusing me to no end! If there's a more efficient way to do this please let me know! Basically the end result needs to be php page with get vars loaded into a div. I know how to do it by hand but this needs to be a function to do it and the get vars won't ever be the same so it needs to be dynamic.