使用更迭或完全在AjaxCall的 [英] use succes or complete in ajaxcall

查看:127
本文介绍了使用更迭或完全在AjaxCall的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,我想知道有什么区别,在下面的AjaxCall

My question is that I want to know what the difference is in the ajaxcall below

如果我代替完成成功 我得到一个空的responseText的错误说: 并与完整的它像它应该是

If I substitute complete for success I get an empty responseText as the error says and with complete it works like it is supposed to

难道成功返回越早就完成了??

Is it that success returns sooner then complete??

$("#formnaw").submit(function(){
    	var fnc = invoerFnc.attr("value");
    	var vnaam = invoerVnaam.attr("value");
    	var anaam = invoerAnaam.attr("value");
    	var str1 = invoerStr1.attr("value");
    	var nr1 = invoerNr1.attr("value");
    	var pc1 = invoerPc1.attr("value");
    	var pl1 = invoerPl1.attr("value");
    	var tel1 = invoerTel1.attr("value");
    	var mob1 = invoerMob1.attr("value");
    	var em1 = invoerEm1.attr("value");
    	var goknop =$("#formnaw > .instelling_go");

    	//we deactiveren de submit knop tijdens het verzenden 
    	goknop.attr({ disabled:true});
    	goknop.blur();
    	//stuur de post variabelen naar livetabs.php
    	$.ajax({
    		type: "POST", url: "registraties/instellingenact.php", data: "actie=wijzignaw&vnaam=" + vnaam +
    		"&anaam=" + anaam + "&functie=" + fnc + "&straat=" + str1 + "&nr=" + nr1 + "&postcode=" + pc1 + "&plaats=" + pl1 + 
    		"&tel=" + tel1 + "&mob=" + mob1 + "&email=" + em1, timeout: 5000,

    		success: function(data,textStatus){
    		alert('bij success');
    			//doe iets
    			}//EINDE success
    			,error: function(XMLHttpRequest, textStatus, errorThrown) { 
    				if(textStatus == 'timeout') { 
    					//doe iets
    				}else if (textStatus == 'error'){
    					//doe iets
    				} 
    			//her-activeer de zend knop
    			goknop.attr({ disabled:false});
    			}//EINDE error
    			,complete: function(data){
    				updatelijst.append(data.responseText + "<br>");
    				if(data.responseText.indexOf("Fout") != -1) {
    					$('#formnaw').find('td.foutnr1').prepend(data.responseText);
    				}else{
    					updatelijst.animate({ opacity: 'show' }, 1000,function(){
    					});
    				}
    				//her-activeer de zend knop
    				goknop.attr({ disabled:false});
    				}//EINDE complete
    	});//EINDE ajax

    	//we stoppen het standaard gedrag van een submit, zodat de pagina niet wordt vernieuwd.
    	return false;
    });

感谢,理查德

thanks, Richard

推荐答案

完整无论是成功后执行错误的回调被处决。

complete executes after either the success or error callback were executed.

也许你应该检查的第二个参数完整提供了。这是一个字符串控股成功过的AjaxCall的类型。

Maybe you should check the second parameter complete offers too. It's a String holding the type of success the ajaxCall had.

在不同的回调进行详细说明一点这里 的jQuery阿贾克斯(选项)

The different callbacks are described a little more in detail here jQuery.ajax( options )

我想你错过了一个事实,即完整成功函数(我知道不一致API)得到不同数据传入。成功仅获取数据,完整获得了整个 XMLHtt prequest 对象。当然也有对数据串没有的responseText 属性。

I guess you missed the fact that the complete and the success function (I know inconsistent API) get different data passed in. success gets only the data, complete gets the whole XMLHttpRequest object. Of course there is no responseText property on the data string.

所以,如果您更换完整成功你也必须更换 data.responseText 数据只。

So if you replace complete with success you also have to replace data.responseText with data only.

成功

功能得到两个   参数:从返回的数据   服务器,根据该格式   '的dataType'参数,和一个字符串   描述状态。

The function gets passed two arguments: The data returned from the server, formatted according to the 'dataType' parameter, and a string describing the status.

完整

功能得到两个   参数:XMLHtt prequest对象   和一个字符串描述的类型   申请成功。

The function gets passed two arguments: The XMLHttpRequest object and a string describing the type of success of the request.

如果您需要访问整个 XMLHtt prequest 的成功回调,我建议尝试这个对象。

If you need to have access to the whole XMLHttpRequest object in the success callback I suggest trying this.

var myXHR = $.ajax({
    ...
    success: function(data, status) {
        ...do whatever with myXHR; e.g. myXHR.responseText...
    },
    ...
});

这篇关于使用更迭或完全在AjaxCall的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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