without_bug
without_bug
  • 发布:2017-02-17 18:03
  • 更新:2019-09-21 16:02
  • 阅读:3099

关于mui.ajax参数data的问题

分类:MUI
mui.ajax('http://192.168.0.50/phalapi/public/demo/?service=Article.egetArticle&articleId=1',{....

直接填入url可以正常请求

var cardInfo = {  
                            service:"Article.egetArticle",  
                            articleId:1  
                        };  
mui.ajax('http://192.168.0.50/phalapi/public/demo/', {  
                        data:JSON.stringify(cardInfo),  
.....  
或者  
mui.ajax('http://192.168.0.50/phalapi/public/demo/', {  
                        data:{  
                            service:"Article.egetArticle",  
                            articleId:1  
                        },  
.....  
或者把data写成  
data:{  
                            'service':"Article.egetArticle",  
                            'articleId':"1"  
                        }

都不可以正常请求,请问我是不是用了假的mui.ajax

2017-02-17 18:03 负责人:无 分享
已邀请:
rh0108

rh0108

headers:{'Content-Type':'application/json'}换成
headers:{'Content-Type':'application/x-www-form-urlencoded'}

  • lifeng_dev

    我试过了,headers:{'Content-Type':'application/json'} 也行的啊

    2019-09-21 12:20

8***@qq.com

8***@qq.com

是不是请求方式问题?post和get

  • lifeng_dev

    get 请求好像也可以直接和 post 一样把参数写在 data 里,get 拼接参数看起来不好看

    2019-09-21 15:57

lifeng_dev

lifeng_dev

官方文档的 ajax 部分写的:
processData
Type: Boolean
为了匹配默认的content-type("application/x-www-form-urlencoded"),
mui默认会将data参数中传入的非字符串类型的数据转变为key1=value&key2=value2格式的查询串;
如果业务需要,希望发送其它格式的数据(比如Document对象),可以设置processData为false

该问题目前已经被锁定, 无法添加新回复