主干获取url数据格式错误 [英] backbone fetch url data formatting error

查看:73
本文介绍了主干获取url数据格式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用主干集合来获取一些数据.在传递给fetch的选项中,我有一个添加到url中的字符串参数:

I am using a backbone collection to fetch some data. in my options passed into fetch I have a string parameter that is added to the url:

options = {data: {sterm: "hello world"}}

当主干对此URL进行提取时,

when backbone runs the fetch on this the url contains

sterm=hello+world

后端不接受的

格式必须为:

which isn't accepted by the backend it needs to be of the format:

sterm=hello%20world

所以我将选项更改为:

options = {data: {sterm: encodeURIComponent("hello world")}}

然后执行提取时,它包含格式正确的查询参数,但是,如果我传入其中包含%的字符串,则encodeURIComponent似乎会将%25更改为%,据我所知是正确的,但是在骨干内部它更改为%2525,这是错误的.有什么方法可以配置主干获取,从而不会将%25更改为%2525?

then when the fetch is executed it contains the correctly formatted query parameter, however if I pass in a string with a % in it, then encodeURIComponent seems to change % for %25 which I understand is correct, but then inside backbone fetch it gets changed to %2525 which is wrong. Is there any way to configure backbones fetch so it doesnt chagne %25 to %2525?

推荐答案

Backbone集合fetch()方法使用 jQuery.ajax()方法,并接受jQuery.ajax()选项作为参数.在jQuery.ajax()方法的文档中,您可能会发现,如果将processData字段定义为false,请求中的数据将不会进行预处理.

Backbone collection fetch() method uses jQuery.ajax() method and accepts jQuery.ajax() options as parameters. In jQuery.ajax() method's documentation you may find that if you define processData field to false, there will be no pre-processing of the data in the request.

options = {
    data: {
        sterm: encodeURIComponent("hello world")
    },
    processData: false
}

这篇关于主干获取url数据格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆