Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

jQuery Ajax Post/Get

Featured Replies

Hey,

 

I'm not sure if this is possible, but if it is, could someone help me as it would save me lots of time.

 

I have 2 spans on a page:

 

Team Fortress 2

Counter Strike: Source

 

Basically when one of these is clicked, I want a variable to be updated so I can use it in a mySQL query.

 

Now obviously the php has already been run, which is why I have my doubts to whether this will work. Then I remembered about ajax, but I suck at it.

 

So basically:

 

Team Fortress 2 is clicked > Ajax request is sent > variable $server is updates with tf2. Without the page reloading.

 

http://api.jquery.com/jQuery.post/

 

Thats where I got it from, but i'm pretty bad with Javascript :( If anyone could help, that;d be awesome.

I think you want to do something like this...

 

Basically the onclick of team fortess 2 element sends an ajax "post" then I'm assuming you are returning the data/html that needs to be updated on the page from with in the php file?

 

$("#idofdiv").click(function(){
$.post("/phpfilename.php",{postvariablename:'datato be sent'},function(responseText){
$("#idofdivtobeupdated").html(responseText);
}
});

  • Author

Ah okay that makes more sense...

 

But what would go in the:

 

phpfilename.php

 

file?

 

Because I want the page to not reload, but still have the div updated. So what would that file have to contain?

phpfilename.php is the file that will be doing the mysql work etc.

 

The page wont be updated the ajax simply sends a call to the php page and the server does the php work and normally you would return a response back to the javascript using a php "return".

 

The javascript can then magically update the page without a refresh

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.