download1002 2015-07-29 04:49
浏览 81

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

i am facing problem in showing ajax call " request response" in alert method.

i checked the ajax call in browser it shows response well, mean ajax call works and it gets some repose but this reponse does not alert in showRepose method

here is my code

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 + '

responseText: 
' + responseText + 
            '

The output div should have already been updated with the responseText.'); 
    }
  • 写回答

1条回答 默认 最新

  • dongyu9667 2015-07-29 04:57
    关注

    I used the target attribute in option but did not mark the div in HTML with id="output2". After I did that it worked. Thanks!

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。