【发布时间】:2014-02-28 10:11:53
【问题描述】:
我使用 C# 作为后端,并希望向我的 C# 后端发出 JSON 对象/字符串请求。
我有这样的 C# 代码(用于 GET 请求):
[WebMethod]
[ScriptMethod(UseHttpGet = true,
ResponseFormat = ResponseFormat.Json, XmlSerializeString = false)]
public static string GetOptionsServiceHttpGet(string variableId)
{
// Do database stuff
string retval = Serialize stuff/function goes here
return retval;
}
javascript前端代码是这样的:
function Variable_Proxy() { }
Variable_Proxy.GetVarOptionsHttpGet =
function (variableId, successCallback, failureCallback) {
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "file.aspx/GetOptionsServiceHttpGet?varId=\"" + variableId + "\",
success: function (data) { successCallback(data); },
error: function (data) { failureCallback(data); }
});
}
如何在点击时发布帖子或其他任何内容以将我的 JSON 对象发送到我的后端?
【问题讨论】:
标签: c# javascript jquery .net