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
https://forums.phpfreaks.com/topic/244337-ajax-div-reload-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.