【发布时间】:2023-04-01 04:20:02
【问题描述】:
JavaScriptSerializer jss = new JavaScriptSerializer();
var seferim = jss.Serialize(sefer);
string asds = seferim.ToString();
asds = HttpUtility.HtmlEncode(asds);
function otobusGetir(id, b, i) {
id = encodeURI(id);
$.ajax({
type: 'POST',
url: 'BiletSatis.aspx/Getir',
contentType: 'application/json;charset=utf-8',
dataType: 'json',
data: '{"id":"' + id + '","Binis":"' + b + '","Inis":"' + i + '"}',
success: function () { },
error: function () { }
})
[网络方法] 公共静态字符串Getir(字符串ID,字符串Binis,字符串Inis) { 字符串 a = id; 字符串 b = HttpUtility.HtmlDecode(id); 返回空值; }
问题是javascript函数不能接受序列化的参数(Uncaught SyntaxError: Unexpected token ILLEGAL)。我怎样才能完全完成这项工作?
问题是这不起作用,而 javascript 函数运行它不能接受参数,如何完全完成这项工作
【问题讨论】:
-
你也可以添加javascript代码吗?您发布的 json 是有效的。您应该能够在 javascript 中反序列化。
-
我不明白你想做什么。你的 json 文字看起来是正确的。 seferim 应该能够毫无问题地作为参数传递给任何 js 函数。你能显示你的代码被破坏了吗?
-
“我怎样才能将像上面这样的数据发送到 javascript 的类”你能改写一下吗?我认为这是问题的主题,但我不确定。
-
函数获取参数时导致的问题,函数无法获取并说 Uncaught SyntaxError: Unexpected token ILLEGAL –
标签: c# javascript json