jQuery Ajax-发布-值损坏

时间:2018-07-17 14:34:44

标签: jquery ajax delphi type-conversion rad-studio

我第一次遇到这种奇怪的情况。我已经使用过Ajax和不同类型的参数。我尝试用contentType来解决,但是似乎没有用。

我尝试使用文档的 UTF-8 和如上所述的contentType之类的格式。

$.ajax({
    url: "/Test",
    type: "POST",
    data: 
    {
        'ID':$(this).attr("ID"),
        'Date':$(this).attr("Date")
    },
    dataType: "json",
    cache: false
})
  

ID = 12345&Date = 01.01.2018 + 00%3A00%3A00 //是

     

ID = 12345&Date = 01.01.2018 00:00:00 //应该是

因此,我无法在Delphi(Rad Studio)中将其转换为double类型:

  

类型变量(UnicodeString)无法转换为Double

1 个答案:

答案 0 :(得分:0)

您的字符串已经过html编码。 HTML在将其转换为日期之前(在您的情况下是两倍?),先在服务器端对其进行解码。

Most ajax libraries will do this automatically.这可能是您的工作,因此日期字符串中的html编码。奇怪的是您以前从未注意到它,因为它是帖子上的正常行为。

要在Delphi中修复,请查看HTTPApp单元。 HTTPDecodeHTMLDecode(以及编码功能)。您应该在 Source / Win32 / Internet 文件夹中找到它。

See this SO question as the above paragraph answer came from there.