从 WebMethod 返回要在 jQuery 中使用的多个值
我有 jquery 使用 ajax/json 来获取元素 ID,然后点击:
[System.Web.Services.WebMethod]
public static string EditPage(string nodeID)
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(Global.conString))
using (SqlCommand cmd = new SqlCommand("contentPageGetDetail", con))
{
cmd.Parameters.Add("@ID", SqlDbType.UniqueIdentifier).Value = Global.SafeSqlLiteral(nodeID, 1);
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(dt);
}
}
if (dt.Count > 0)
{
string pageTitle = dt.Rows[0]["Title"].toString();
string contentID = dt.Rows[0]["ContentID"].toString();
return pageTitle, contentID, nodeID;
}
else
{
return "Failed";
}
}
当返回时,我想将从存储过程返回的所有内容获取到成功部分中的 jquery 方法,并设置隐藏字段、下拉值和文本字段中的标题。
在 jQuery 中,我尝试使用“pageTitle”,但它未定义。在显示表单之前,我需要在 jQuery 方面执行哪些操作来获取返回的内容并填充 Web 表单中的字段?
I have jquery using ajax/json to grab an elements ID and then hits:
[System.Web.Services.WebMethod]
public static string EditPage(string nodeID)
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(Global.conString))
using (SqlCommand cmd = new SqlCommand("contentPageGetDetail", con))
{
cmd.Parameters.Add("@ID", SqlDbType.UniqueIdentifier).Value = Global.SafeSqlLiteral(nodeID, 1);
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(dt);
}
}
if (dt.Count > 0)
{
string pageTitle = dt.Rows[0]["Title"].toString();
string contentID = dt.Rows[0]["ContentID"].toString();
return pageTitle, contentID, nodeID;
}
else
{
return "Failed";
}
}
When it's time to return I want to grab all content returned from the stored procedure back to the jquery method in the success section and set a hiddenfield, dropdown value, and a title in a textfield.
In the jQuery I tried using "pageTitle" but it came up undefined. What do I need to do jQuery side to grab whats being returned and populate fields in my Web Form before showing the form?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要创建一个结构或类来返回:
如果您
在 AJAX 调用中传递:,您将获得一个 JSON 回复,您可以像这样解析它:
You'll need to create a struct or class to return:
If you pass:
in the AJAX call, you'll get a JSON reply, which you can parse like:
==== jquery 端:
假设您正在使用 jquery 的 AJAX 调用,请执行以下操作:
您需要直接查看 Web 服务输出(只需导航到它,就好像它是网页一样)以确保您的 jQuery 选择器正确。
==== jquery side:
Assuming you're using the AJAX call of jquery do something like this:
You'll need to look at the webservice output directly (just navigate to it as if it were a webpage) to make sure your jQuery selector is correct.
如果您想使用从 jquery 返回的字符串,请尝试:
msg.d 将保存您从 Web 服务调用返回的字符串。如果要返回多个字符串,请尝试在它们之间添加预定义的字符串,并在 jquery success 函数中拆分它们。喜欢:
If you want to use the string you return from jquery try:
msg.d will hold the string you return from your webservice call. If you want to return multiple strings, try to add a predefined string between them and split them in your jquery success function. like: