ajax webservice 数组,jQuery中通过ajax调用webservice传递数组参数的问题实例详解.doc...

jQuery 中通过 ajax 调用 webservice传递数组参数的问题实例详解

本文通过实例给大家详细介绍jQuery中通过ajax调 用webservice传递数组参数的相关资料,需要的朋友可以 参考下

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

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

客户端代码如下:

$. ajax({

url:"test/xxx. asmx〃,

type:’ POS T’,

dataType :, xml’, time out:,

data : {name:”zha ngsarT,tags :『aa' "bb' "cc"]}, err or:function (xml) {

ale rt (xml. resp onseText):

},

success:function(xm 1) {

alert ("0 K");

});

服务端代码如下:

[WebMe thod]

publ icXmlDocume ntxxx(strin gname,strin g口 tags) {nb sp;

returnst h;nbsp;

总是抛出异常.

问题出现在这里:

下面是HTTP数据:

POST. com/x xx. asmx/xxx HTTP/1. 1 H ost: center, cmis. htpc. c Conn ection:keep -alive

Conte nt_Length:5 5

Cache-Co ntrol: max-a ge=O Origi n: x. com

User -Agent:Mozi lla/5. 0(Win dowsNT5. 1)A ppleWebKit/535. 1 (KHTML,likeGecko)

Chrome/14. 0.835. 186Saf ari/535. 1

Content-Typ e:applicati on/x-www-fo rm-urlencod ed;charset=UTF-8

Acce pt :applicat ion/xml, tex t/xml,氺/氺;q =0. 01 Refe rer:. com/xxx . aspx

Acce pt-Encoding :gzip, defla te, sdch

Ac cept-Langua ge: zh-CN, zh : q=0. 8

Acc ept-Charset :GBK, utf-8;q=0. 7,*;q=0 ? 3

name=zh angsanamp;t ags%5B%5D=a aamp;tags%5 B%5D=bbamp: tags°/o5B%5D=cc

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

POST/x xx. asmx/xxx HTTP/1. 1

Hos t: xxx. com

Content-Typ e:applicati on/x-www-fo rm-urlencod ed

Content -Length: len gth

name=s tringamp; ta gs=stringam p; tags=stri ng

比较上面粗体,post的数据除了问题.正确的应该如下: name=zhangs anamp; tags=aaamp; tags=bbamp; tags=cc 看来问题出在j query, ajax上面了.见代码(jque

ry. 1. 8. 3. js )

function buildParams (prefix, obj ,traditiona 1,add) {

varn ame;

if (jQ uery. isArra y (obj)) {nbs p;

//Seria lizearrayit em.

jQuery . each (obj, f unction (i,v ) {

if (trad itional | | rb racket, test (prefix)) {n bsp; //Tre ateacharray itemasascal ar.

add (pref ix,v);

}else {

//Ifarra yitemisnon- scalar(arra yorobject), encodeits

//numericin dextoresolv edeserializ ationambigu ityissues.

//Notethat rack(asof. . )can’tcurre ntlydeseria

lize

//nes tedarrayspr operly, anda ttemptingto dosomaycaus e

//aserve rerror. Poss iblefixesar etomodifyra ck’ s//de

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值