我面临的问题显示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.');
}
我在选项中使用了target
属性,但没有在HTML中使用id="output2"
标记div。在我这样做之后,它起作用了。谢谢!