Ajax Not Fully Posting Data To Php File
The problems with your code is you are not encoding the values. So that will mess up the values. Plus you have a leading jQuery does the encoding for you when you use an object. And you really should use You have to escape(encode) sent parameters to the server, to avoid confusion of characters like ampersand(&) Change this: To this: Encode your string properly before firing off the Ajax. To make your life easier, why not just use object notation and let Solution 1:
&
which makes no sense. You can manually encode all the values with encodeURIComponent or you can let jQuery handle that for you. functionSend_upload_news() {
var get_title = document.getElementById('Germ_title');
var get_date = document.getElementById('Germ_date');
varData = {
input_title : get_title.value,
input_date : get_date.value,
input_content : $("div.nicEdit-main").html()
};
$.ajax({
url : "uploadNews.php",
type: "POST",
dataType: 'text',
data : Data,
success: function(result){alert(result);},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert('There is an error, screenshot this error and send to Admin : ' +textStatus+" - "+errorThrown);
}
});
nicEditors.findEditor( "Germ_content" ).setContent( '' );
get_title.value = "";
get_date.value = "";
$('html, body').animate({ scrollTop: 0 }, 'slow');
}
var
so your application is not full of global variables.Solution 2:
var Data = '&input_title='+input_title+'&input_date='+input_date+'&input_content='+input_content;
varData = '&input_title='+encodeURIComponent(input_title)+'&input_date='+encodeURIComponent(input_date)+'&input_content='+encodeURIComponent(input_content);
Solution 3:
var title = encodeURIComponent(input_title);
var date = encodeURIComponent(input_date);
var content = encodeURIComponent(input_content);
varData = 'input_title='+title+'&input_date='+date+'&input_content='+content;
$.ajax({
...
data : Data,
...
jQuery
handle the encoding?$.ajax({...data : {
input_title:input_title,
input_date:input_date,
input_content:input_content
},...
Post a Comment for "Ajax Not Fully Posting Data To Php File"