Jump to content
Mudsaf

jQuery GET method PHP

Recommended Posts

Hello, im wondering how does jQuery get method work. Since it should not reload the page again? I've seen this, but how to example make this more automated whitout refreshing "http://mudsaf.info/games/index.php".

$.ajax({  url: url,  data: data,  success: success,  dataType: dataType});

Share this post


Link to post
Share on other sites

The refreshing might be the result of not cancelling the event's default action when you click on a link. Remember to return false and call preventDefault() in your event handlers.

Share this post


Link to post
Share on other sites

I'm not sure what you're asking. That is an example of using AJAX with jQuery. If the variable success assigned to the success property of the object literal being passed to the ajax method is actually a function and supports the passing in of the response as a param, then you are all set. Unless there's more to the example I'm not getting...?

Edited by thescientist

Share this post


Link to post
Share on other sites

My point was i'd like to surf pages 1, 2, 3 ... and so on whitout actually "refreshing" the page, but refreshing game table only. Example url

http://mudsaf.info/games/index.php?pageid=1tohttp://mudsaf.info/games/index.php?pageid=2

Could you give me example aswell if thats possible.

Share this post


Link to post
Share on other sites

All your PHP script needs to do is echo data. Since you want to refresh only your game table, then the data that gets echoed should not be a complete HTML document. Echo exactly what you need and nothing more. Your javascript will receive that data in the function that you pass in the success parameter of $.ajax. A basic success function will look like this:

function mySuccess (response, status, jqXHR) {   alert (response);}

Obviously, you'll want to do something more interesting with the response data, but before you script that, you should try something this basic as a test. Also, this example assumes you are echoing a plain string. jQuery also lets you receive data formatted as another data type.

Edited by Deirdre's Dad

Share this post


Link to post
Share on other sites

On page 1 you will have to put your table inside a div. For example

<div id="content">// Your table goes here</div>

Then your JQuery will be

$.get("http://mudsaf.info/games/index.php?pageid=2", function(responceData){$("#content").html(responceData);});

responceData will be the data you echo-ed in your php script after you have tested that $_GET['pageid'] is equal to 2. You PHP script will have to be on the the index.php page but you can put it in a different page and and then change the URL to point to that page. I hope this way of sending an AJAX request is much more easier to digest.

Share this post


Link to post
Share on other sites
On page 1 you will have to put your table inside a div. For example
<div id="content">// Your table goes here</div>

Then your JQuery will be

$.get("http://mudsaf.info/games/index.php?pageid=2", function(responceData){$("#content").html(responceData);});

responceData will be the data you echo-ed in your php script after you have tested that $_GET['pageid'] is equal to 2. You PHP script will have to be on the the index.php page but you can put it in a different page and and then change the URL to point to that page. I hope this way of sending an AJAX request is much more easier to digest.

There is a function designed to do this: http://api.jquery.com/load/ Also, it is spelled "response". It's pretty important to spell variables correctly so that people reading you code stand a chance of remembering your variable names.

Share this post


Link to post
Share on other sites

it doesn't really matter if it is spelled wrong, per se. if it is spelled the same way all the way throughout the code (as in his example) then it wont cause any errors. If you're just out to be the spelling/grammar police, then do so more gracefully, since it's just a programming forum and there are no rules to how your actually name your variables, other than the required syntax of the language.

Edited by thescientist

Share this post


Link to post
Share on other sites
it doesn't really matter if it is spelled wrong, per se. if it is spelled the same way all the way throughout the code (as in his example) then it wont cause any errors. If you're just out to be the spelling/grammar police, then do so more gracefully, since it's just a programming forum and there are no rules to how your actually name your variables, other than the required syntax of the language.
What?Do you know why we have conventions on variable naming? I'll give you a clue: it isn't to make the code pretty.

Share this post


Link to post
Share on other sites

callumacrae, I think everyone welcomes a seasoned developer on the board. But there are some matters you may wish to hold back on until you've absorbed more of the spirit of the board, who we are, and what the members are looking for.

Share this post


Link to post
Share on other sites
What? Do you know why we have conventions on variable naming? I'll give you a clue: it isn't to make the code pretty.
you do know that typos and mistakes exist right? you're really going to flog a person over one letter in a variable in a post on a message board? Are you going to be this critical when members from other countries post code using variable names in their own language?

Share this post


Link to post
Share on other sites
callumacrae, I think everyone welcomes a seasoned developer on the board. But there are some matters you may wish to hold back on until you've absorbed more of the spirit of the board, who we are, and what the members are looking for.
It is our responsibility as experienced developers to ensure that less experienced developers do not develop habit habits or make the same mistakes we did. The amount of time I have spent searching for incorrectly spelled variables... I did not "flog" him, merely pointed it out. Edited by callumacrae

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...