I don't know why ajax instead of sending request to specified url, it makes request to the same link. Only this ajax request in the whole page is acting weird. Please give me some light over this issue
$(document).ready(function(){
$("#phoneForm").submit(function(){
$.ajax({
type: "POST",
url: "http://example.com/chat.pl",
data: $('form#phoneForm').serialize(),
success: function(data)
{
if(data==="1")
{
$('#phoneResult').html('Thank you');//hide button and show thank you
$('#phone_modal').modal('toggle');
}
},
error: function(){
alert("failure");
}
});
});
});
Form content:
<form class='horizontal' id='phoneForm' name='phoneForm' accept-charset='utf-8'>
<input type='text' pattern='\\d*' id='phoneNumber' name='number'/>
<button class='btn btn-dark' type='submit'>submit</button>
</form>
Edited:
I added the ajax error function. Its giving the alert before ajax submission and give request to the same page