Forum Moderators: open

Message Too Old, No Replies

Jquery invalid label problems

PHP to Jquery get vars

         

jamina1

7:43 pm on Sep 2, 2009 (gmt 0)

10+ Year Member



Help!
I'm trying to write a function and I've got it all working, except that I keep getting an "invalid label error".

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()
});
});
}

and it would be called like so:

<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.

jamina1

7:51 pm on Sep 2, 2009 (gmt 0)

10+ Year Member



I have fixed this by adding quotes around both items in the label so it would be 'variable1':'value','variable2':'value'

whoisgregg

7:56 pm on Sep 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, jamina1!

Glad you got it sorted and that you posted back with your solution. :)