gpt4 book ai didi

javascript - Ajax成功功能好像不起作用

转载 作者:行者123 更新时间:2023-12-03 08:30:04 26 4
gpt4 key购买 nike

有人可以帮助我吗?我的成功功能似乎不起作用。 beforesend 正在工作,我已经检查了变量 s。在 ajax 之前这是正确的,因此所有验证都是正确的。请看一下..

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 + "&currently_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:info@northernpropertyreports.com.au">info@northernpropertyreports.com.au</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")
}
}
});
}
}

最佳答案

也许发布您的 PHP 脚本将更好地帮助我们理解问题,但是,对于初学者来说......

我注意到了这一点:

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,

我可以建议:

data: {
'data': {
'property_type': property_type,
'bedrooms': bedroom,
'bathroom': bathroom,
'condition': condition
}
},

在 PHP 脚本上:

<?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);

关于您的成功功能:

success: function( response ) {
if(response.message) {
console.log(response.message);
}
}

此外,来自jQuery.ajax() API documentation

Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks are deprecated as of jQuery 1.8. To prepare your code for their eventual removal, use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.

关于javascript - Ajax成功功能好像不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33379391/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com