当我使用以下代码时,它按预期工作:
TINY.box.show({url:target, post:$("form[name='currentSearch']").serialize(),
width:650, mask:true, close:true, maskid:'boxMask', boxid:'popupBox',
openjs:function(){initialiseDataTable()}});
当我像这样使用数组$("form[name='currentSearch']").serialize()
时:
var postData = $("form[name='currentSearch']").serializeArray();
postData.push({flag : '1'});
TINY.box.show({url:target, post:postData, width:650, mask:true, close:true, maskid:'boxMask',
boxid:'popupBox', openjs:function(){initialiseDataTable()}});
我收到错误:
NS_ERROR_XPC_JSOBJECT_HAS_NO_FUNCTION_NAMED: 'JavaScript component does not have a method named: "available"' when calling method: [nsIInputStream::available]
[Break On This Error]
...',c,true); x.setRequestHeader('Content-type','application/x-www-form-urlencoded'...
我不喜欢使用“数组”,因为它比向表单添加动态输入更简单,更优雅。但是我不是用JavaScript编写的,因此有人可以告诉我为什么会出现这个问题并且有可能发布数组吗?
这是我认为发生错误的tinybox代码:
var x=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');
x.onreadystatechange=function(){
if(x.readyState==4&&x.status==200){p.style.backgroundImage=''; TINY.box.psh(x.responseText,a,w,h)}
};
if(k){
x.open('POST',c,true); x.setRequestHeader('Content-type','application/x-www-form-urlencoded'); x.send(k)
}else{
x.open('GET',c,true); x.send(null)
}
答案 0 :(得分:1)
似乎TinyBox不使用jQuery,因此您需要序列化数组,然后可以将其与请求一起使用。在这种情况下,jQuery param很方便。这是jQuery在将数组传递给$.ajax
var formData = $("form[name='currentSearch']").serializeArray();
formData.push({name : 'flag', value : '1'});
var postData = $.param(formData); // serialize it
TINY.box.show({url:target, post:postData, width:650, mask:true, close:true, maskid:'boxMask',
boxid:'popupBox', openjs:function(){initialiseDataTable()}});