I'm using an ajax call to call a php function where inside it I have an alert. But the alert not fire but return me the code of the javascript (seen inside console). How can I use an laert inside an ajax call?
Please don't answer to use function success to check my data etc etc.. because I need alert inside the call please.
This is my code simplified:
$('.form-booking').each(function(){
$form = $(this);
$.ajax({
async: false,
type: 'POST',
url: someurl.php'',
data: $form.serialize(),
success: function (msg) {
console.log(msg);
}
});
});
php part in someurl.php
<?php
....
//some code
....
if($some_condition){
?>
<script>
if (confirm('Do you wanna go over?')) {
//other code
} else {
window.location.href = 'otherurl.php';
}
</script>
<?php
}
?>
This code does't show alert if the condition is true but I see inside console in tab Net
the response and the code of the script in javascript
<php
// some code
echo $some_condition
Then in your main file in your success function:
function(data){
if(data){
if (confirm('Do you wanna go over?')) {
//other code
} else {
window.location.href = 'otherurl.php';
}
}