我有这段 JavaScript 代码,可以在单击按钮时执行 ajax 请求。
$('#allinea').click(function(e){
e.preventDefault();
var password = $('#password').val();
$.ajax({
type: "POST",
url: "db_align.php",
data: {password:password},
complete: function(data){
data1=data.split("|");
if(data1[0]=="Successo"){
$("#per_all").fadeTo(200,0.1,
function(){
$(this).find('img').attr("src",'../images/ok.png');
$(this).find('.right').html(data1[1]).promise().done(function(){
$(this).fadeTo(900,1);
});
});
}else if(data1[0]=="Errore"){
$("#per_all").fadeTo(200,0.1,
function(){
$(this).find('img').attr("src",'../images/alert.png');
$(this).find('.right').html(data1[1]).promise().done(function(){
$(this).fadeTo(900,1);
});
});
}
}
}); //chiudo $.ajax
});
php 页面返回“Successo|Allineamento riuscito”,我在 firebug 中看到它正确,但 js 返回错误:
Type error: data.split is not a function
data1=data.split("|");
我在应用程序中的任何地方都使用此代码,没有任何不便。这次我做错了什么?
就我所见,顺便说一句,这不是一个数组,所以这应该可以正常工作,没有任何不便!
最佳答案
jQuery 将返回 jqXHR在这里,这意味着您可能需要执行 data.responseText
,而不是直接访问 data
。
关于javascript - 分割错误 : split is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31776289/