【问题标题】:json key is not sent correctly in ajax requestajax 请求中未正确发送 json 密钥
【发布时间】:2015-09-23 23:12:30
【问题描述】:

我正在使用 $.ajax (jquery) 发出请求。我正在发送一个参数对象。但是,特定密钥未正确编码。

var parameters = {
        "sdk":0,
        "hub":"something.es",
        "site":"something.es",
        "section":"replay",
        "slug1":"vod",
        "slug2":"samsung-tv-app",
        "output":"xml_vast2",
        "url":"http://www.something.es",
        "description_url":"http://www.something.es",
        "country":"es",
        "somecms":"i3",
        "player":"i3",
        "vpos":position,
        "sitesection":fromSection,
        "contenttype":"videos",
        "pagename":pageName,
        "title":title
    };
    $.ajax({
        url :         baseURL,
        data :        parameters,
...

但是,请求看起来像这样(看 &section=replay 显示为 §ion=replay )

http://analytics.something.com/ads/tagsv2/video/?&sdk=0&hub=zzzzz.es&site=yyy.es§ion=replay&slug1=vod&slug2=samsung-tv-app&output=xml_vast2&url=http%3A%2F%2Fwww.something.es&description_url=http%3A%2F%2Fwww.something.es&country=es&somecms=i3&player=i3&vpos =preroll&sitesection=shows&contenttype=videos&pagename=desfile。"

我做了不同的组合,使用',',没有引号也没有办法。最有趣的是,如果我将键更改为'asection'甚至'Section'(带有大写S),它工作正常.

我应该怎么做才能正确发送密钥?

【问题讨论】:

  • 我认为请求进行得很好。你检查过控制台吗?

标签: javascript ajax json url-rewriting character-encoding


【解决方案1】:

它发生了,因为&sect maps to § in HTML。这对您的应用程序内部来说应该不是问题(因为您的请求与 HTML 无关)。如果您想向用户显示 URL,请将其转义。

【讨论】:

  • 问题是我的客户不接受它并要求我将参数 s 发布为 x=123&section=aaaa&y=4444。如何对密钥进行编码以以这种方式显示它?
  • &sect 在 HTML 中显示为 §。它应该与您的请求无关。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-12-21
  • 2012-07-28
  • 1970-01-01
  • 2020-07-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多