加载ajax调用和我的问题
loading for ajax call and my problem with it
为什么空值后$(idinput).val() == ''
不隐藏加载ajax调用#loadingDiv
:
$('#loadingDiv')
.hide() // hide it initially
.ajaxStart(function() {
$(this).fadeIn('slow');
})
.ajaxStop(function() {
$(this).fadeOut('slow');
});
$('.auto_complete').keyup(function () {
var specific = '.' + $(this).closest('div.auto_box').find('b').attr('class');
//var cl_list = '.' + $(this).closest('div.auto_box').find('ul').attr('class');
var id = '#' + this.id;
var url = $(id).attr('class');
var idinput = '#'+$(specific + ' input').attr('id');
var dataObj = $(this).closest('form').serialize();
$.ajax({
type: "POST",
dataType: 'json',
url: url,
data: dataObj,
cache: false,
success: function (data) {
//alert(url)
var cl_list = '.' + $('.auto_box '+ specific +' ul').attr('class');
var id_name = $(cl_list).attr('id');
$(cl_list).show().html('');
if (data == 0) {
$(cl_list).show().html('<p><b>وجود ندارد</b></p>');
}
else {
$.each(data, function (a, b) {
//alert(b.name)
$('<p id="' + b.name + '">' + b.name + '</p>').appendTo(cl_list);
});
$(cl_list + ' p').click(function (e) {
e.preventDefault();
var ac = $(this).attr('id');
$('<b>' + ac + '، <input type="text" name="'+id_name+'[]" value="' + ac + '" style="border: none; display: none;" /></b>').appendTo($('.auto_box ' + specific + ' span'));
$(this).remove();
return false;
});
$('.auto_box span b').live('click', function (e) {
e.preventDefault();
$(this).remove();
return false;
});
}
///////////////////////////////////here/////////////////////////////////////////////
if ($(idinput).val() == '') {
alert('cl_list')
$(cl_list).hide()
$(cl_list + " p").hide().remove();
$('.auto_complete').val('');
$(".list_name").show().html('');
};
///////////////////////////////////end//////////////////////////////////////////////
$('body').click(function () {
$(cl_list + " p").hide().remove();
$('.auto_complete').val('');
$(cl_list).show().html('');
$(cl_list).css('display','none')
});
},
"error": function (x, y, z) {
// callback to run if an error occurs
alert("An error has occured:'n" + x + "'n" + y + "'n" + z);
}
});
});
看起来您在语句末尾缺少了几个分号。试试这个:
$('#loadingDiv')
.hide() // hide it initially
.ajaxStart(function() {
$(this).fadeIn('slow');
})
.ajaxStop(function() {
$(this).fadeOut('slow');
});
$('.auto_complete').keyup(function () {
var specific = '.' + $(this).closest('div.auto_box').find('b').attr('class');
//var cl_list = '.' + $(this).closest('div.auto_box').find('ul').attr('class');
var id = '#' + this.id;
var url = $(id).attr('class');
var idinput = '#'+$(specific + ' input').attr('id');
var dataObj = $(this).closest('form').serialize();
$.ajax({
type: "POST",
dataType: 'json',
url: url,
data: dataObj,
cache: false,
success: function (data) {
//alert(url);
var cl_list = '.' + $('.auto_box '+ specific +' ul').attr('class');
var id_name = $(cl_list).attr('id');
$(cl_list).show().html('');
if (data == 0) {
$(cl_list).show().html('<p><b>وجود ندارد</b></p>');
}
else {
$.each(data, function (a, b) {
//alert(b.name);
$('<p id="' + b.name + '">' + b.name + '</p>').appendTo(cl_list);
});
$(cl_list + ' p').click(function (e) {
e.preventDefault();
var ac = $(this).attr('id');
$('<b>' + ac + '، <input type="text" name="'+id_name+'[]" value="' + ac + '" style="border: none; display: none;" /></b>').appendTo($('.auto_box ' + specific + ' span'));
$(this).remove();
return false;
});
$('.auto_box span b').live('click', function (e) {
e.preventDefault();
$(this).remove();
return false;
});
}
if ($(idinput).val() == '') {
alert('cl_list');
$(cl_list).hide();
$(cl_list + " p").hide().remove();
$('.auto_complete').val('');
$(".list_name").show().html('');
};
$('body').click(function () {
$(cl_list + " p").hide().remove();
$('.auto_complete').val('');
$(cl_list).show().html('');
$(cl_list).css('display','none');
});
},
"error": function (x, y, z) {
// callback to run if an error occurs
alert("An error has occured:'n" + x + "'n" + y + "'n" + z);
}
});
});
尝试:
if(!$(idinput).val())
我发誓我也有同样的错误,但找不到项目。
相关文章:
- 我的jQuery插件参数没有正确启动,遇到了问题
- 在我的SPA应用程序中集成Facebook共享的问题
- 我不知道我的编码有什么问题.(JavaScript)
- 为什么不'我的窗口滚动事件根本没有启动.其他答案没有解决问题
- 我的流星路线出了什么问题
- MathJax正在复制我的方程式——为什么以及如何解决这个问题
- 在将javascript附加到我的html中时遇到问题
- 表单提交问题,如何在我的URL末尾获得ID的值
- 我的CSS/Javascript下拉菜单测试代码出了什么问题
- 在我的网站上创建一个在1-10之间不断变化的数字时遇到了问题.Javascript
- 我的代码很完美,但我现在不知道为什么我发现了问题
- 跨浏览器问题:如何调试我的网站'在windows PC的safari上的行为
- Html、css和jQuery.我的代码有问题
- 在 html 上切换我的问题
- 尝试从URL下载并用node.js保存到文件中.这是我的问题
- 我如何随机显示我的问题,所以它现在总是一样的?(JavaScript)
- 困惑为什么这个javascript导致我的问题.定义了类和原型方法
- 加载ajax调用和我的问题
- Javascript找到我的问题
- 是我的问题还是Visual Studio 2010的问题