javascript - PHP code inside jquery not working -
//my jquery
$(document).ready(function() { var form = $('#form1'); // contact form var submit = $('#submit1'); // submit button var alert = $('.alert1'); // alert div show alert message // form submit event form.on('submit', function(e) { e.preventdefault(); // prevent default form submit // sending ajax request through jquery $.ajax({ url: 'giftcard_check.php', // form action url type: 'post', // form submit method get/post datatype: 'html', // request type html/json/xml data: form.serialize(), // serialize form data beforesend: function() { alert.fadeout(); submit.html('checking....'); // change submit button text }, success: function(data) { alert.html(data).fadein(); // fade in response data form.trigger('reset'); // reset form submit.html('apply'); // reset submit button text var $container = $("#result1"); var refreshid = setinterval(function() { $container.load("result.php?code=<?php echo $variable; ?>"); }, 500); }, error: function(e) { console.log(e) } }); }); });
the above code not working while using php code inside jquery. if iam not using php code working fine. want send session variables page (result.php). how can solve this. there method.
use below code . assing php session javascript variable. make sure code in side php file . php not work inside .js file
var sessionid = "<?php echo $_session['id']; ?>"; $(document).ready(function() { var form = $('#form1'); // contact form var submit = $('#submit1'); // submit button var alert = $('.alert1'); // alert div show alert message form.on('submit', function(e) { e.preventdefault(); // prevent default form submit // sending ajax request through jquery $.ajax({ url: 'giftcard_check.php', // form action url type: 'post', // form submit method get/post datatype: 'html', // request type html/json/xml data: form.serialize(), // serialize form data beforesend: function() { alert.fadeout(); submit.html('checking....'); // change submit button text }, success: function(data) { alert.html(data).fadein(); // fade in response data form.trigger('reset'); // reset form submit.html('apply'); // reset submit button text var $container = $("#result1"); var refreshid = setinterval(function() { $container.load("result.php?code="+sessionid); }, 500); }, error: function(e) { console.log(e) } }); }); });
Comments
Post a Comment