I am working on an application that involves getting the entire page content from a page using javascript and dumping the html to the database.On the page I have various components that will be parsed and stored using a ajax
request.I do it like this.
function saveContent(){
var $getContent = $('#mainWrap').clone();
$getContent.find('.textBox, .pictureBox').removeAttr('id');
var saveContent = $getContent.wrap('<div></div>').html();
var getBodyStyle=$('body').attr('style');
var auto="auto";
$.ajax({
url:"save.php",
type:"POST",
dataType:"text",
data:"txtComp="+saveContent+"&auto="+auto+"&pageId="+pageId+"&webId="+webId+"&userId="+userId+"&bodyStyle="+getBodyStyle,
success:function(data){
var options = {"text":data,"layout":"topCenter","type":"success","animateOpen": {"opacity": "show"}};
setTimeout(function(){noty(options)}, 1000);
//$('#draftMsg').html(data).fadeIn(500);
}
});
}
Now I have social media components like facebook,twitter.When I try to save the facebook component it is not save entirely as it contains some parameters that are present in the script with '&'.
<div style="z-index: 1001; height: 560px; width: 413px; top: -20px; left: 121.5px;" id="com-IADDFSGNHLU7WNR3WM2KC3I8DA2DOIC6" class="facebookBox contentBox boxStyle">
<div class="blankDiv"></div>
<iframe class="facebookBoxObject" allowtransparency="true" style="border: medium none; overflow: hidden; height: 560px; width: 413px;" src="https://www.facebook.com/plugins/likebox.php?api_key=117096311791424&locale=en_US&height=560&header=true&show_faces=true&stream=true&width=413&href=http://www.facebook.com/cbil360" frameborder="0" scrolling="no">
</iframe>
</div>
The above is the content I want to store to the database and I get it when I say console.log
but in the database it stores only the below content
<div style="z-index: 1001; height: 388px; width: 283px; top: -20px; left: 120.5px;" id="com-IADDFSGNHLU7WNR3WM2KC3I8DA2DOIC6" class="facebookBox contentBox boxStyle">
<div class="blankDiv"></div><iframe class="facebookBoxObject" allowtransparency="true" style="border: medium none; overflow: hidden; height: 388px; width: 283px;" src="https://www.facebook.com/plugins/likebox.php?api_key=117096311791424
It breaks after the api_key
parameter as it has & after that.I am not asure as I don't get any error for this.Tried to debug but,not to a conclusion yet.
Please correct where am I going wrong.
Update: The query I am using is
$query = "insert into tbl_revision (userId,revisionContent,webId,pageId,status,saveType,dateAdded) values ('".$_SESSION['UserId']."','$revisionContent','$webId','$pageId','$status','$saveType','$toDate')"