tags:

views:

76

answers:

1

Ok so I have a php page with data dynamically outputs depending on a $_GET variable ['file']. I have another page (index.php) which has a jQuery script that uses the load() function to load the php page. I have a list of links and when you click on one, it needs to change the $_GET variable to load, then refresh the load() jQuery variable. Heres a snippet:

$("#remote-files").load("data.php?file=wat.txt");
$(".link1").mousedown(function() {
 $("#remote-files").load("data.php?file=link1.txt");
});

As you can see it loads the data into a div with the ID of remote-files. Is there a better way to do this, like update the page with the new get variable instead of redefining a new load function?

+2  A: 

Not entirely sure what you're asking, or whether what I'm suggesting is much better, but...

function loadData(filename) {
    $("#remote-files").load("data.php?file=" + filename);
}

loadData("wat.txt");

$(".link1").click(function() {
    loadData("link1.txt");
});

That would reduce some duplication anyway.

Andy Hume