Jump to content

Post a bunch of HTML code and got "html[object HTMLDivElement]"


everisk

Recommended Posts

Hi,

 

I'm trying to POST HTML code of a webpage by using AJAX, but I got 'html[object HTMLDivElement]' as a response. Below is my code. Thanks!

 

print '<div id="html_content" name="html_content" style="display: none;">';
print $html;
print '</div>';
print 'View your email in: <input type="submit" name="type" id="type" value="Preview1" onClick="sendRequest(this.value);"> <input type="submit" name="type" id="type" value="Preview2" onClick="sendRequest(this.value);">';

 

Ajax Code

function createRequestObject() {

   var req;

   if(window.XMLHttpRequest){
      req = new XMLHttpRequest();
   } else if(window.ActiveXObject) {
      req = new ActiveXObject("Microsoft.XMLHTTP");
   } else {
      alert('Problem creating the XMLHttpRequest object');
   }

   return req;

}

var http = createRequestObject();

function sendRequest(content_type, html_content) {
var url = "get_content.php";
var htm = document.getElementById("html_content");

var params = "type=" + encodeURIComponent(content_type) + "html" + document.getElementById("html_content");

http.open("POST", url, "true");

http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");

http.onreadystatechange = handleResponse;

http.send(params);

}

function handleResponse() {
document.getElementById('loadingImage').style.display = 'block';

  if (http.readyState == 4 && http.status == 200) { 
      var response = http.responseText;
      if(response) {
	document.getElementById('loadingImage').style.display = 'none';
	document.getElementById('content').innerHTML = response;
      }
  }
}

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.