斗士狗 2018-09-21 11:27 采纳率: 0%
浏览 35

AJAX之后未定义jQuery

I've got a weird error where jQuery is not defined after an ajax function.

If I run jquery function before the ajax function, it works fine. If I run it after the ajax function, it says jQuery undefined.

Here's my ajax function, is there anything here that would cause jquery to be undefined?

$.ajax({
    type : "post",
    dataType : "json",
    url : ad_Ajax.ajaxurl,
    data : {
        action: "ad_store_results",
        final_response_identity_score : final_response_identity_score,
        final_response_integrity_score : final_response_integrity_score,
        final_response_inner_score : final_response_inner_score,
        final_response_insight_score : final_response_insight_score,
        final_response_influence_score : final_response_influence_score,
        final_practical_indentity_score : final_practical_indentity_score,
        final_practical_integrity_score : final_practical_integrity_score,
        final_practical_inner_score : final_practical_inner_score,
        final_practical_insight_score : final_practical_insight_score,
        final_practical_influence_score : final_practical_influence_score,
        final_fostered_identity_score : final_fostered_identity_score,
        final_fostered_integrity_score : final_fostered_integrity_score,
        final_fostered_inner_score : final_fostered_inner_score,
        final_fostered_insight_score : final_fostered_insight_score,
        final_fostered_influence_score : final_fostered_influence_score,
        fostered_score_array: fostered_score_array,
        nonce: nonce},
    success: function(response) {
        if(response.type == "success") {
           $(".i[data-id='5']").addClass('hide');
           $('.health-check__final').addClass('hide');
           $('.i--results').removeClass('hide');
           $('html,body').animate({ scrollTop:$('.i--results').offset().top}, 'slow');


           // Update scores
           $('.health-check-result[data-i="identity"] span').html(final_fostered_identity_score);
           $('.health-check-result[data-i="integrity"] span').html(final_fostered_integrity_score);
           $('.health-check-result[data-i="inner strength"] span').html(final_fostered_inner_score);
           $('.health-check-result[data-i="insight"] span').html(final_fostered_insight_score);
           $('.health-check-result[data-i="influence"] span').html(final_fostered_influence_score);

           // Add post ID to form
           $(".gform_hidden").val(response.post_id);
        }
        else {
           console.log(response);
        }
    },
    error: function(response) {
        console.log(response);
    }
});

The bit that isn't working is a gravity form (wordpress plugin). I can't actually edit this code though, and it works prior to the ajax call.

                <script type='text/javascript'>jQuery(document).ready(function($){gformInitSpinner( 1, 'http://local.mleadership.com/app/plugins/gravityforms/images/spinner.gif' );jQuery('#gform_ajax_frame_1').on('load',function(){var contents = jQuery(this).contents().find('*').html();var is_postback = contents.indexOf('GF_AJAX_POSTBACK') >= 0;if(!is_postback){return;}var form_content = jQuery(this).contents().find('#gform_wrapper_1');var is_confirmation = jQuery(this).contents().find('#gform_confirmation_wrapper_1').length > 0;var is_redirect = contents.indexOf('gformRedirect(){') >= 0;var is_form = form_content.length > 0 && ! is_redirect && ! is_confirmation;if(is_form){jQuery('#gform_wrapper_1').html(form_content.html());if(form_content.hasClass('gform_validation_error')){jQuery('#gform_wrapper_1').addClass('gform_validation_error');} else {jQuery('#gform_wrapper_1').removeClass('gform_validation_error');}setTimeout( function() { /* delay the scroll by 50 milliseconds to fix a bug in chrome */ jQuery(document).scrollTop(jQuery('#gform_wrapper_1').offset().top); }, 50 );if(window['gformInitDatepicker']) {gformInitDatepicker();}if(window['gformInitPriceFields']) {gformInitPriceFields();}var current_page = jQuery('#gform_source_page_number_1').val();gformInitSpinner( 1, 'http://local.mleadership.com/app/plugins/gravityforms/images/spinner.gif' );jQuery(document).trigger('gform_page_loaded', [1, current_page]);window['gf_submitting_1'] = false;}else if(!is_redirect){var confirmation_content = jQuery(this).contents().find('.GF_AJAX_POSTBACK').html();if(!confirmation_content){confirmation_content = contents;}setTimeout(function(){jQuery('#gform_wrapper_1').replaceWith(confirmation_content);jQuery(document).scrollTop(jQuery('#gf_1').offset().top);jQuery(document).trigger('gform_confirmation_loaded', [1]);window['gf_submitting_1'] = false;}, 50);}else{jQuery('#gform_1').append(contents);if(window['gformRedirect']) {gformRedirect();}}jQuery(document).trigger('gform_post_render', [1, current_page]);} );} );</script><script type='text/javascript'> if(typeof gf_global == 'undefined') var gf_global = {"gf_currency_config":{"name":"Pound Sterling","symbol_left":"&#163;","symbol_right":"","symbol_padding":" ","thousand_separator":",","decimal_separator":".","decimals":2},"base_url":"http:\/\/local.mleadership.com\/app\/plugins\/gravityforms","number_formats":[],"spinnerUrl":"http:\/\/local.mleadership.com\/app\/plugins\/gravityforms\/images\/spinner.gif"};jQuery(document).bind('gform_post_render', function(event, formId, currentPage){if(formId == 1) {} } );jQuery(document).bind('gform_post_conditional_logic', function(event, formId, fields, isInit){} );</script><script type='text/javascript'> jQuery(document).ready(function(){jQuery(document).trigger('gform_post_render', [1, 1]) } ); </script>

Thanks for any help!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容
    • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
    • ¥20 yolov5自定义Prune报错,如何解决?