阿贾克斯成功的功能似乎不工作 [英] Ajax success function does not seem to work

查看:127
本文介绍了阿贾克斯成功的功能似乎不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以someoone帮助我。我的成功的功能似乎并没有工作。该beforesend的工作,我已经检查了变量s。这是阿贾克斯之前,真正让所有的验证是正确的。请看看..

 函数enquiry_validations(){
    如果(多个){
        VAR URL =HTTP://本地主机:9080 / C /可湿性粉剂内容/主题/澳元/ mailer.php;
        jQuery.ajax({
            键入:POST,
            网址:网址,
            数据:房产类型=+房产类型+&放大器;卧室=+卧室+&放大器;卫生间=+卫生间+&放大器;条件=+状态+&放大器; est_size =+ EST +&放大器;停车= +填料+与& special_feature =+ spl_fet +与&其他=+ OTH +与& unit_no =+ unt_no +与& street_no =+ street_no +与& street_name =+ street_name + &功放;工作室=+郊区+&放大器;状态=+状态+&放大器;关系=+关系+&放大器;目标=+目标+&放大器;电池=+ time_to_cell +&放大器; currently_listed_n = + currently_listed +&放大器;如first_name =+ FIRST_NAME +&放大器; sur_name =+姓氏+&安培;电话=+电话+&放大器;电子邮件=+电子邮件,

            错误:功能(数据){
                的console.log(数据);

            },
            beforeSend:函数(){
                的console.log('happeneing');
                。jQuery的('#阿贾克斯装载机)显示();
                jQuery的('#阿贾克斯装载机)HTML('< IMG SRC =HTTP://本地主机:9080 / C /可湿性粉剂内容/主题/澳元/图片/ AJAX-loader.gif>')。
            },
            成功:函数(结果){
                。jQuery的('#阿贾克斯装载机)隐藏();
                执行console.log(结果);

                如果(结果== 0){
                    的console.log(无结果)
                }
                如果(结果=='1'){
                    jQuery.fancybox('&LT; D​​IV CLASS =澳大利亚游泳会烯流行&GT;&LT; H3&GT;感谢您使用北楼盘报告&LT; / H3&GT;&LT; P&GT;您的北报表重新presentative忙让你的财产申报准备就绪,将在触摸48小时内与您的自由报告&LT; BR&GT;所有咨询请发邮件至:&LT; A href="mailto:info@northernpropertyreports.com.au">info@northernpropertyreports.com.au</a></p></div>');
                    jQuery的(#房产类型)VAL('')。
                    jQuery的('#卧室)VAL('')。
                    jQuery的('#浴室)VAL('')。
                    jQuery的('#条件)VAL('')。
                    jQuery的('#EST)VAL('')。
                    jQuery的('#停车)VAL('')。
                    jQuery的(输入[类型=复选框']#检查:检查)丙('检查',假)。
                    jQuery的('#OTH)VAL('')。
                    jQuery的('#un_no)VAL('')。
                    jQuery的('#Street_no)VAL('')。
                    jQuery的('#street_name)VAL('')。
                    jQuery的('#郊区)VAL('')。
                    jQuery的('#国家)VAL('')。
                    jQuery的('#relationship_to_Property)VAL('')。
                    jQuery的('#purpose_of_request)VAL('')。
                    jQuery的('#time_to_sell)VAL('')。
                    jQuery的(输入[类型=无线电]:选中)。PROP('检查',假);;
                    jQuery的('#FIRST_NAME)VAL('')。
                    jQuery的('#姓氏)VAL('')。
                    jQuery的('#电话')VAL('')。
                    jQuery的('#邮件)VAL('')。
                    jQuery的('#confirm_email)VAL('')。
                    jQuery的(输入[类型=复选框']#同意:检查)丙('检查',假)。
                    的console.log(是结果)
                }
            }
        });
    }
}
 

解决方案

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

我注意到了这一点:

 数据:房产类型=+房产类型+&放大器;卧室=+卧室+&放大器;卫生间=+卫生间+&放大器;条件=+状态+&放大器; est_size =+ EST +&放大器;停车=+包装+&放大器; special_feature =+ spl_fet +&放大器;其他=+ OTH +&放大器; unit_no =+ unt_no +&放大器; street_no =+ street_no +&放大器; street_name =+ street_name +&放大器;工作室=+郊区+&放大器;状态=+状态+&放大器;关系=+关系+&放大器;目标=+目标+&放大器;电池=+ time_to_cell +&放大器; currently_listed_n =+ currently_listed +&放大器;如first_name =+ FIRST_NAME +&放大器; sur_name =+姓氏+&安培;电话=+电话+&放大器;电子邮件=+电子邮件,
 

我建议:

 数据:{
        '数据': {
            房产类型:房产类型,
            卧室:卧室,
            浴室:卫生间,
            条件:条件
         }
},
 

而在PHP脚本:

 &LT; PHP
   $数据=阵列();
   $响应=阵列();

   如果(使用isset($ _ POST ['数据']){
       $数据= $ _ POST ['数据'];
       $响应['code'] =200;
       $响应['消息'] =你好!属性类型是。 $数据['房产类型'];
   }

  回声json_en code($响应);
 

和您的成功功能:

 成功:函数(响应){
    如果(response.message){
        执行console.log(response.message);
    }
}
 

此外,从 jQuery.ajax()API文档

  

德precation注意:在 jqXHR.success() jqXHR.error() jqXHR.complete() 回调德$ pcated为的jQuery 1.8 p $ 。要ppare您的code $ P $他们最终消除,使用 jqXHR.done() jqXHR.fail() jqXHR.always() 代替。

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 + "&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")
                }
            }
        });
    }
}

解决方案

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 + "&currently_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(), 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.

这篇关于阿贾克斯成功的功能似乎不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆