freestate
Aug 20th 2008, 8:10 am
I am using an AJAX script to add links to a 'My Links' section on a navigation menu.
I have the links being added to a database, and My Links then displays the relevant records from the database.
The script is working perfectly to update the database, and return a 'link added' message.
However, because it's all done without a page refresh, the My Links section does not update to reflect the changes made.
Can you help sort this out so that links are added/removed to the database (this is already done) AND the My Links section updates to show the current output from the database?
I am willing to pay (a little!) to get this done - for someone who knows what they're doing, I'm sure it's a 5 minute job.
The My links section are held in a div with an id of 'quicklinks', and the AJAX code being used to add to the database is as follows:
/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}
var http = createObject();
/* -------------------------- */
/* INSERT */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function insert(str) {
// Optional: Show a waiting message in the layer with ID login_response
document.getElementById('response_advice').innerHTML = "Adding link..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
//var stuff = encodeURI(document.getElementById('site_url').value);
//var site_name = encodeURI(document.getElementById('site_name').value);
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'insert.php?'+str+'&nocache = '+nocache);
http.onreadystatechange = insertReply;
http.send(null);
}
function insertReply() {
if(http.readyState == 4){
var response = http.responseText;
// else if login is ok show a message: "Site added+ site URL".
document.getElementById('insert_response').innerHTML = ''+response;
document.getElementById('response_advice').innerHTML = "Link added"
}
}
/* -------------------------- */
/* REMOVE */
/* -------------------------- */
function remove(str) {
// Optional: Show a waiting message in the layer with ID login_response
document.getElementById('response_advice').innerHTML = "Removing link..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
//var stuff = encodeURI(document.getElementById('site_url').value);
//var site_name = encodeURI(document.getElementById('site_name').value);
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'remove.php?'+str+'&nocache = '+nocache);
http.onreadystatechange = removeReply;
http.send(null);
}
function removeReply() {
if(http.readyState == 4){
var response = http.responseText;
// else if login is ok show a message: "Site added+ site URL".
document.getElementById('insert_response').innerHTML = ''+response;
document.getElementById('response_advice').innerHTML = "Link removed"
}
}
Let me know if you can help!
I have the links being added to a database, and My Links then displays the relevant records from the database.
The script is working perfectly to update the database, and return a 'link added' message.
However, because it's all done without a page refresh, the My Links section does not update to reflect the changes made.
Can you help sort this out so that links are added/removed to the database (this is already done) AND the My Links section updates to show the current output from the database?
I am willing to pay (a little!) to get this done - for someone who knows what they're doing, I'm sure it's a 5 minute job.
The My links section are held in a div with an id of 'quicklinks', and the AJAX code being used to add to the database is as follows:
/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}
var http = createObject();
/* -------------------------- */
/* INSERT */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function insert(str) {
// Optional: Show a waiting message in the layer with ID login_response
document.getElementById('response_advice').innerHTML = "Adding link..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
//var stuff = encodeURI(document.getElementById('site_url').value);
//var site_name = encodeURI(document.getElementById('site_name').value);
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'insert.php?'+str+'&nocache = '+nocache);
http.onreadystatechange = insertReply;
http.send(null);
}
function insertReply() {
if(http.readyState == 4){
var response = http.responseText;
// else if login is ok show a message: "Site added+ site URL".
document.getElementById('insert_response').innerHTML = ''+response;
document.getElementById('response_advice').innerHTML = "Link added"
}
}
/* -------------------------- */
/* REMOVE */
/* -------------------------- */
function remove(str) {
// Optional: Show a waiting message in the layer with ID login_response
document.getElementById('response_advice').innerHTML = "Removing link..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
//var stuff = encodeURI(document.getElementById('site_url').value);
//var site_name = encodeURI(document.getElementById('site_name').value);
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'remove.php?'+str+'&nocache = '+nocache);
http.onreadystatechange = removeReply;
http.send(null);
}
function removeReply() {
if(http.readyState == 4){
var response = http.responseText;
// else if login is ok show a message: "Site added+ site URL".
document.getElementById('insert_response').innerHTML = ''+response;
document.getElementById('response_advice').innerHTML = "Link removed"
}
}
Let me know if you can help!