everisk Posted April 4, 2008 Share Posted April 4, 2008 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 https://forums.phpfreaks.com/topic/99549-post-a-bunch-of-html-code-and-got-htmlobject-htmldivelement/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.