传递给 JavaScript 类对象在代码隐藏中序列化
本文关键字:代码 隐藏 序列化 对象 JavaScript | 更新日期: 2023-09-27 18:28:14
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函数不能接受序列化的参数(未捕获的语法错误:意外的令牌ILLEGAL(。我怎样才能完全完成这项工作?
问题是这不起作用,而javascript函数运行它不能接受参数,怎么能完全完成这项工作
尝试如下:
function otobusGetir(id, b, i) {
$.ajax({
type: 'POST',
url: 'BiletSatis.aspx/Getir',
contentType: 'application/json;charset=utf-8',
dataType: 'json',
data: JSON.stringify({ id: id, Binis: b, Inis: i }),
success: function () { },
error: function () { }
});
}
并调用该函数:
otobusGetir(123, 'foo bar', 'baz');
和页面方法:
[WebMethod]
public static string Getir(string id, string Binis, string Inis)
{
// don't use any Html decoding here. The parameters will
// already be properly formatted so you can use them directly
return null;
}