Reputation: 299
I have an entire html page from html to /html, including script tags, css, etc, stored in a database. I am using jquery to get the variable from a php script based on the id of the row in the database from another website. This all works perfectly but the BODY and HEAD tags are removed - the rest of the html is intact. Can anyone shed some light on this? here is my code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
function getListing(postid){
$.ajax({
type: "POST",
url: "http://my-website.com/url.php",
data: postid,
dataType: "html",
cache: false,
success: function(html) {
$("html").html(html);
}
});
}
getListing("postid=6943");
});
</script>
and the php is pretty basic:
<?php header("Access-Control-Allow-Origin: *");?>
<? if($_POST['postid']) {
$postid = $_POST['postid'];
// get html into a variable here *(code romved)*
echo $html;
}
?>
Upvotes: 1
Views: 785
Reputation: 414096
Why not just use a <form>
and post it? A lot simpler, and it's a pretty basic browser function already:
$(function() {
$('body').append($('<form/>', {
id: 'newForm',
action: "http://my-website.com/url.php",
method: "POST"
}).append($('<input/>', { name: 'postid' value: '6943' })));
$('#newForm').submit();
});
When you post a form and the server responds with an HTML page, the browser loads it over the old page.
Upvotes: 1