jquery - Post with AJAX and PHP - How is this really working -
1.) post content (i.e. text) id , variables in php in post.php file?
2.) call php, "if ($_post['promotion'])". how define _post in ajax , in php?
basically want php make post.
html:
<input type="text" id="promo_headline"> <button id="btnpostpromotion">post promotion</button>
jquery:
$(document).ready(function(){ $('#btnpostpromotion').click(function() { $.ajax({ type : 'post', url : 'post.php', datatype : 'json', data: $('#promo_headline').val(), success : function(data){ if (data.error === true) $('#errormodal').modal("show"); }, error : function(xmlhttprequest, textstatus, errorthrown) { $('#errormodal').modal("show"); } }); return false; }); });
php:
if ($_post['promotion']) { $promo_headline = $_post['promo_headline']; }
if want $_post['promotion']
available in php, send object key of promotion
.
$.ajax({ url : '...', type : 'post', data : { promotion : $('#promo_headline').val() }, ... });
as note kinda makes me sad seeing jquery.val()
being used when more efficient (and cross browser friendly) to:
document.getelementbyid('promo_headline').value;
Comments
Post a Comment