2

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.