Reputation: 1836
Can someoone help me. My success function does not seem to work. The beforesend is working and i have checked the variable s. It is true before the ajax so all the validations are correct. Please have a look..
function enquiry_validations() {
if (s) {
var url = "http://localhost:9080/c/wp-content/themes/aussie/mailer.php";
jQuery.ajax({
type: "POST",
url: url,
data: "property_type=" + property_type + "&bedrooms=" + bedroom + "&bathroom=" + bathroom + "&condition=" + condition + "&est_size=" + est + "&parking=" + packing + "&special_feature=" + spl_fet + "&other=" + oth + "&unit_no=" + unt_no + "&street_no=" + street_no + "&street_name=" + street_name + "&studio=" + suburb + "&State=" + state + "&relation=" + relationship + "&purpose=" + purpose + "&cell=" + time_to_cell + "¤tly_listed_n=" + currently_listed + "&first_name=" + first_name + "&sur_name=" + last_name + "&telephone=" + telephone + "&email=" + email,
error: function (data) {
console.log(data);
},
beforeSend: function () {
console.log('happeneing');
jQuery('#ajax-loader').show();
jQuery('#ajax-loader').html('<img src="http://localhost:9080/c/wp-content/themes/aussie/images/ajax-loader.gif">');
},
success: function (result) {
jQuery('#ajax-loader').hide();
console.log(result);
if (result == '0') {
console.log("No Result")
}
if (result == '1') {
jQuery.fancybox('<div class="aussi-en-pop"><h3>Thank you for using Northern Property Reports.</h3> <p>Your Northern Reports representative is busy getting your Property Report ready and will be in touch within 48 hours with your free report. <br> All enquiries please email : <a href="mailto:[email protected]">[email protected]</a></p></div>');
jQuery("#Property_type").val('');
jQuery('#bedrooms').val('');
jQuery('#bathrooms').val('');
jQuery('#condition').val('');
jQuery('#est').val('');
jQuery('#parking').val('');
jQuery("input[type='checkbox']#chk:checked").prop('checked', false);
jQuery('#oth').val('');
jQuery('#un_no').val('');
jQuery('#Street_no').val('');
jQuery('#street_name').val('');
jQuery('#suburb').val('');
jQuery('#state').val('');
jQuery('#relationship_to_Property').val('');
jQuery('#purpose_of_request').val('');
jQuery('#time_to_sell').val('');
jQuery("input[type='radio']:checked").prop('checked', false);;
jQuery('#first_name').val('');
jQuery('#last_name').val('');
jQuery('#telephone').val('');
jQuery('#email').val('');
jQuery('#confirm_email').val('');
jQuery("input[type='checkbox']#agree:checked").prop('checked', false);
console.log("YES Result")
}
}
});
}
}
Upvotes: 0
Views: 281
Reputation: 11808
data: {"property_type": property_type ,
"bedrooms": bedroom,
"bathroom" : bathroom ,
"condition" : condition ,
"est_size" : est ,
"parking" : packing ,
"special_feature" : spl_fet ,
"other" : oth ,
"unit_no" : unt_no ,
"street_no" : street_no ,
"street_name" : street_name ,
"studio" : suburb ,
"State" : state ,
"relation" : relationship ,
"purpose" : purpose ,
"cell" : time_to_cell ,
"currently_listed_n" : currently_listed ,
"first_name" : first_name ,
"sur_name" : last_name ,
"telephone" : telephone ,
"email" : email}
Use this format to send or pass the data from jquery
Upvotes: 0
Reputation:
Perhaps posting your PHP script will better help us understand the problem, but, for starters...
I noticed this:
data: "property_type=" + property_type + "&bedrooms=" + bedroom + "&bathroom=" + bathroom + "&condition=" + condition + "&est_size=" + est + "&parking=" + packing + "&special_feature=" + spl_fet + "&other=" + oth + "&unit_no=" + unt_no + "&street_no=" + street_no + "&street_name=" + street_name + "&studio=" + suburb + "&State=" + state + "&relation=" + relationship + "&purpose=" + purpose + "&cell=" + time_to_cell + "¤tly_listed_n=" + currently_listed + "&first_name=" + first_name + "&sur_name=" + last_name + "&telephone=" + telephone + "&email=" + email,
May I suggest:
data: {
'data': {
'property_type': property_type,
'bedrooms': bedroom,
'bathroom': bathroom,
'condition': condition
}
},
And on the PHP script:
<?php
$data = array();
$response = array();
if(isset($_POST['data']) {
$data = $_POST['data'];
$response['code'] = "200";
$response['message'] = "Hi! The property type is " . $data['property_type'];
}
echo json_encode($response);
And on your success
function:
success: function( response ) {
if(response.message) {
console.log(response.message);
}
}
Also, from the jQuery.ajax() API documentation
Deprecation Notice: The
jqXHR.success()
,jqXHR.error()
, andjqXHR.complete()
callbacks are deprecated as of jQuery 1.8. To prepare your code for their eventual removal, usejqXHR.done()
,jqXHR.fail()
, andjqXHR.always()
instead.
Upvotes: 1