I'm confused on how to refresh an HTML table using AJAX.
I'm not the developer of the site, so I dont have the server side information. I cant find anyway to reload the table on this page: http://www.roblox.com/Poison-Horns-item?id=62152671
I understand that you need to request a document for AJAX to work, but I cant find the document on the page. Im just the user >.> - which makes me assume ajax is mostly for the people who develop the sites.
You won't be able to reload just part of the page unless you have some way of getting that part. From a developer perspective, they can request just the table data from the server and show it on the screen, updating automatically.
You, being just the user, get the entire page when you load it. So no, you won't be able to just get the table data without getting the rest of the page. Even if you want just the table part, you have to request the entire page.
Your best bet is to have a script that reloads the entire page. This can be done with a web page and iFrame with the site loaded in the iFrame and a script that just reloads the frame every so often.
<iframe id="frame" src="http://mysite.com"></iframe>
setInterval(reload,1000)
function reload() {
document.getElementById("frame").src=document.getElementById("frame").src;
}
The above code will reload the page every 1000ms
.
Regarding AJAX being quicker than reloading the page:
This is true, if you only request the data using AJAX and then update the page on the client side. In this case, there is minimal data transfer between client and server so everything is faster. In your case, you'd still have to request the entire page even if you did it with AJAX. Websites with AJAX have an API that allows the client to request specific information from the server to make things faster. You don't have that here.
From what I understand, you just want something that checks the price of an item and alert you if it's below a threshold. If this is the case, I would use a Chrome Extension that allows you to inject JS into webpages. Something like this.
The following jQuery selector gets you the price of the first item. You can adjust the threshold price and interval (300000ms = 5 minutes
).
var price = $("#UserSalesTab > table > tbody > tr:nth-child(2) > td:nth-child(3) > b").html().match(/[0-9]+/)[0]
if (price < 100) alert("BUY");
setInterval(reload, 300000)