Jump to content

Ajax Div Reload Question


mikebarbaro

Recommended Posts

I have an ajax script that submits form information onto a database after submitting and displays a success message. Underneath is a list of previous submissions similar to a status feed. I'd like to reload the div where the previous submissions are to display the newly submitted post, just like it does when you post a status on Facebook and it automatically shows up.

 

Here is my ajax code:

 

/* ---------------------------- */
/* 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() {
// Optional: Show a waiting message in the layer with ID login_response
document.getElementById('insert_response').innerHTML = '<div style="padding:5px; background-color:#F90; border: #F30 1px solid;">Posting...</div>'
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var status= encodeURI(document.getElementById('status').value);
var username= encodeURI(document.getElementById('username').value);




// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'processstatus_ajax.php?status='+status+'&username='+username+'&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 = '<div style="padding:5px; background-color:#F90; border: #F30 1px solid;">Your status has been posted.<br><img src=images/icons/rsvps.png width=18px> <span style="font-size:18px;"><a href="javascript:streamPublish();">Share with Facebook</a></span></div>';
document.getElementById('inner_form').innerHTML = '';


}
}

 

Any help is appreciated! I've been working on this for days but cannot figure it out.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.