本文介绍了.serialize()Javascript中的变量数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可用的变量列表,我想通过$ .ajax发布.使用.serialize函数时,我必须保留哪种格式?我不断收到此错误:

I have a list of variables available to me and I want to send it via $.ajax post. What format would I have to keep these in to use the function .serialize? I keep getting this error:

对象空白"没有方法序列化"

Object 'blank' has no method 'serialize'

我试图使它们成为数组,并且尝试了jQuery.param().我觉得这很简单,但似乎无法理解.谢谢!

I've tried to make them an array and I've tried jQuery.param(). I have a feeling this is simple but I can't seem to get it. Thanks!

var $data = jQuery.makeArray(attachmentId = attachmentID, action = 'rename', oldName = filename, newName, bucketName, oldFolderName, newFolderName, projectId = PID, businessId = BID);
var serializedData = $data.serializeArray();
//alert(theurl);

$.ajax({ type: "post", url: theurl, data: serializedData, dataType: 'json', success:  reCreateTree });  

推荐答案

.serialize适用于表单元素:

.serialize is for form elements:

$.ajax文档表示data选项:

因此,您所需要做的就是传递一个对象.例如:

So all you need to do is passing an object. For example:

$.ajax({ 
    type: "post", 
    url: theurl, 
    data: {                             // <-- just pass an object
          attachmentId: attachmentID,
          action: 'rename',
          // ...
    },
    dataType: 'json', 
    success:  reCreateTree 
});  

这篇关于.serialize()Javascript中的变量数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 11:36