当我使用以下代码时,它可以按预期工作:

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)
}

最佳答案

TinyBox似乎不使用jQuery,因此您需要序列化可以与请求一起使用的数组。在这种情况下,jQuery param派上了用场。这是将数组传递给$.ajax时jQuery内部执行的操作

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()}});

09-25 17:18
查看更多