如何调用jquery ajax表单插件的函数showResponse

时间:2015-07-29 04:49:59

标签: php jquery ajax wordpress

我在显示ajax电话时面临问题"请求回复"在警报方法。

我在浏览器中检查了ajax调用它显示响应很好,意味着ajax调用工作并且它得到一些休息但是这个响应在showRepose方法中没有警告

这是我的代码

jQuery(window).ready(function()     {

    var atts = <?php echo json_encode($atts ); ?>;
    var options = { 
        target:'#output2',   // target element(s) to be updated with server response 


        // other available options: 
         url:"<?php echo admin_url('admin-ajax.php'); ?>",        // override for form's 'action' attribute 
        //url:"<?php echo PLUGIN_URI; ?>check-ajax.php",
        data:{'btn_send_form_email':'1','process_ajax':'1','atts':JSON.stringify(atts),'action':'get_post_information'},
        type:"post",        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 

        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:showResponse , // post-submit callback 

     }; 

    // bind to the form's submit event 

    jQuery("form[name='wemblo_frontend_form_<?php echo $form_id;?>").submit(function() 
    { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        jQuery(this).ajaxSubmit(options); 

        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
    }); 


    function showResponse(responseText, statusText, xhr, $form)  
    { 
        // for normal html responses, the first argument to the success callback 
        // is the XMLHttpRequest object's responseText property 

        // if the ajaxSubmit method was passed an Options Object with the dataType 
        // property set to 'xml' then the first argument to the success callback 
        // is the XMLHttpRequest object's responseXML property 

        // if the ajaxSubmit method was passed an Options Object with the dataType 
        // property set to 'json' then the first argument to the success callback 
        // is the json data object returned by the server 

        alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
            '\n\nThe output div should have already been updated with the responseText.'); 
    }

1 个答案:

答案 0 :(得分:-1)

我在选项中使用了target属性,但未使用id="output2"在HTML中标记div。在我这样做之后它起作用了。谢谢!