Passing javascript variables to another php page -
i have select list in using javascript selected values want selected values pass through php file init.php can use variables in mysql query. javascript code follows:
$(document).ready(function(){ var e = document.getelementbyid("product"); var pro = e.options[e.selectedindex].text; alert(pro); }); $('select').change(function(){ var e = document.getelementbyid("city"); var cit = e.options[e.selectedindex].text; alert(cit);
i have used ajax send variables init.php. ajax code below not working,can tell whats issue in code:
$.ajax({ url: 'init.php', type: 'post', data: { x:'cit',y:'pro' }, success: function(data) { console.log(data); } });
and in init.php have written :
<?php $var1 = $_post['y']; $var2 = $_post['x']; $result = "select amount ". _db_prefix_ ."demo_detail product = '". $var1 ."' , city = '" . $var2 . "' "; //echo json_encode($result);
can alter url
line include / make sure you're referring init.php
relative root of directory?
so should this:
$.ajax({ url: '/init.php', type: 'post', data: { x:'cit',y:'pro' }, success: function(data) { console.log(data); } });
i don't know enough sure there's chance ajax making post request wrong url.
Comments
Post a Comment