jQuery Code
$(document).ready(function(){
$('.btn').click(function(){
// get text field value
var userName = $('.myField').val();
var emailAddress = 'myemail@server.com';
// ajax request and response in function
$.ajax({
url: 'process.php',
type: 'POST',
data: 'passVarOne='+userName+'&passVarTwo='+emailAddress,
success:function(responseAnyNameHere) {
$('.responseArea').html(responseAnyNameHere);
},
statusCode:{
404:function(){
$('.error').html("Page not found!");
},
200:function(){
$('.error-not').html("Page found! Its okay.");
}
}
}).error(function(){
$('.error').html("Some error");
}).success(function(){
$('.success').html("Success");
}).complete(function(){
$('.success').html("Action completed");
});
});
});
PHP Code
<?php
if( isset($_POST['passVarOne']) || isset($_POST['passVarTwo']) ) {
echo "Response received ... <br>";
echo "Name: " . $_POST['passVarOne'];
echo "<br>";
echo "Email: " . $_POST['passVarTwo'];
}
?>
jQuery version is 3.3.1
The Form is below, without form tag
<input type="text" class="form-control myField">
<br>
<button class="btn btn-default">Submit</button>
Problem: The response/result is being received. But the call backs are not working. Error messages "$.ajax(...).error is not a function" I have tried
.on("error",function(){...}
but no success. I have tried
jQuery.ajax
I have tried
(function($) { ... })(jQuery);
I have tried .live, .bind and var jqueryObj = $; and some more but call backs are not working or there is some other issue. I am using it on WAMP Server v2.5.
I want the .error, .success and .complete to be working. I have tried searching here and seen other threads but I found that .error was depricated in old jQuery version but I am using new version.