here ajax call is not happening inside function, outside function it is working,
anyone can help in spotting the error
$('#submit').on("click", function(){
var B = $('#search').val();
alert (B);
$.ajax({
url:"hi.php",
type:"POST",
data:{A :10},
success: function(data){
console.log (data);
},
});
})
2
Answers
May be default submit event is firing before this function. You can prevent this by e.preventDefault().
If button type is submit it will refresh your page and you will not get a desired behavior. So you need to use either a normal button or event.PreventDefault(); to make sure it will not refresh your page.
for more you can visit here