$.ajax({url: "test/xxx.asmx",type: 'POST',dataType: 'xml',timeout: ,data: { name: "zhangsan", tags: ["aa", "bb", "cc"] },error: function {alert;},success: function; 

看来问题出在jquery.ajax上面了.见代码

function buildParams(prefix, obj, traditional, add) {var name;if  { // Serialize array item.jQuery.each {if (traditional || rbracket.test { // Treat each array item as a scalar.add;} else {// If array item is non-scalar , encode its// numeric index to resolve deserialization ambiguity issues.// Note that rack  can't currently deserialize// nested arrays properly, and attempting to do so may cause// a server error. Possible fixes are to modify rack's// deserialization algorithm or to provide an option or flag// to force array serialization to be shallow.//ytx buildParams(prefix, v, traditional, add);//buildParams(prefix + "[" + (typeof v === "object" ? i : "") + "]", v, traditional, add);}});} else if (!traditional && jQuery.type {// Serialize object item.for  {buildParams(prefix + "[" + name + "]", obj[name], traditional, add);}} else {// Serialize scalar item.add;}}

出问题的代码在22行,我修改成21行那样就行了.

下面通过实例给大家说明比较直观些,更方便大家了解。

本人的项目中通过jquery.ajax调用webservice.

[WebMethod]public XmlDocument xxx(string name, string [] tags ){ return sth; }

POST http://xxx.com/xxx.asmx/xxx HTTP/1.1Host: center.cmis.htpc.com.cnConnection: keep-aliveContent-Length: 55Cache-Control: max-age=0Origin: http://xxx.comUser-Agent: Mozilla/5.0  AppleWebKit/535.1  Chrome/14.0.835.186 Safari/535.1Content-Type: application/x-www-form-urlencoded; charset=UTF-8Accept: application/xml, text/xml, */*; q=0.01Referer: http://xxx.com/xxx.aspxAccept-Encoding: gzip,deflate,sdchAccept-Language: zh-CN,zh;q=0.8Accept-Charset: GBK,utf-8;q=0.7,*;q=0.3name=zhangsan&tags%5B%5D=aa&tags%5B%5D=bb&tags%5B%5D=cc
POST /xxx.asmx/xxx HTTP/1.1Host: xxx.comContent-Type: application/x-www-form-urlencodedContent-Length: lengthname=string&tags=string&tags=string

不过,我对js/jquery都是一知半解的,希望不要引起别的后遗症,呵呵.

而它期望的格式是如下的:

比较上面粗体,post的数据除了问题. 正确的应该如下:

结论:

以上所述是小编给大家介绍的jQuery中通过ajax调用webservice传递数组参数的问题实例详解的相关知识,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

name=zhangsan&tags=aa&tags=bb&tags=cc

服务端代码如下:

客户端代码如下:

相关文章

网站地图xml地图