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;
      }
  }
}

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.