javascript - calling jquery AJAX dynamically -
the following code not working me , don't know why...
this js code:
var geteventsfunctionscript = document.createelement('script'); geteventsfunctionscript.setattribute('type', 'text/javascript'); geteventsfunctionscript.innerhtml = "function getevents(){$.ajax({url:'myphp_file.php',type:'post',data:{'ajaxdata':'1'},success:function(response){alert('ajax executed!!');}});}"; w.document.body.appendchild(geteventsfunctionscript);
this php code:
if (isset($_post['ajaxdata'])) { exit; }
my problem not working, ajax never executed (i never see alert)
could give idea why not working?
thank much
you need call function afterwards:
geteventsfunctionscript.innerhtml = "function getevents() { $.ajax({ url: 'myphp_file.php', type: 'post', data: { 'ajaxdata': '1' }, success: function (response) { alert('ajax executed!!'); } }); } getevents();";
Comments
Post a Comment