使用jQuery的方法的getJSON与ASP.NET Web窗体 [英] Using jQuery's getJSON method with an ASP.NET Web Form
本文介绍了使用jQuery的方法的getJSON与ASP.NET Web窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何去调用一个方法使用的getJSON方法jQuery的ASP.NET Web窗体页?
的目的是这样的:
- 在一个列表项,点击
- 的值被发送到服务器
- 服务器用的东西相关的列表,使用JSON格式的响应
- 填充二次箱
我不想使用一个UpdatePanel,我这样做几百个使用ASP.NET MVC框架次,但使用Web窗体不能看着办吧!
到目前为止,我所能做的一切,包括呼叫服务器,它只是不调用正确的方法。
谢谢,
基隆
有些code:
的jQuery(文件)。就绪(函数(){
jQuery的(#<%= AreaListBox.ClientID%GT;)。点击(函数(){
updateRegions(jQuery的(本).VAL());
});
});功能updateRegions(areaID表示){
jQuery.getJSON('/ Locations.aspx / GetRegions',
{areaID表示areaID表示},
功能(数据,textStatus){
调试器;
});
}
解决方案
下面是一个简约的例子应该有希望让你开始:
<%@页面语言=C#%>
<%@导入命名空间=System.Web.Services%GT;<脚本=服务器>
[的WebMethod]
公共静态字符串GetRegions(INT areaID表示)
{
返回富+ areaID表示;
}
< / SCRIPT><!DOCTYPE HTML>
< HTML的xmlns =http://www.w3.org/1999/xhtml>
<头=服务器>
<标题> jQuery和页面方法< /标题>
<脚本类型=文/ JavaScript的SRC =http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js>< / SCRIPT>
< /头>
<身体GT;
<脚本类型=文/ JavaScript的>
$(函数(){
VAR areaID表示= 42;
$阿贾克斯({
键入:POST,
网址:Default.aspx的/ GetRegions
数据:{areaID表示:+ areaID表示+},
的contentType:应用/ JSON的;字符集= UTF-8,
数据类型:JSON
成功:功能(数据){
警报(data.d);
}
});
});
< / SCRIPT>
< /身体GT;
< / HTML>
How do I go about calling a method on an ASP.NET Web Form page using the getJSON method on jQuery?
The goal is this:
- User clicks on a list item
- The value is sent to the server
- Server responds with related list of stuff, formatted using JSON
- Populate secondary box
I don't want to use an UpdatePanel, I've done this hundreds on times using the ASP.NET MVC Framework, but can't figure it out using Web Forms!
So far, I can do everything, including calling the server, it just doesn't call the right method.
Thanks,
Kieron
Some code:
jQuery(document).ready(function() {
jQuery("#<%= AreaListBox.ClientID %>").click(function() {
updateRegions(jQuery(this).val());
});
});
function updateRegions(areaId) {
jQuery.getJSON('/Locations.aspx/GetRegions',
{ areaId: areaId },
function (data, textStatus) {
debugger;
});
}
解决方案
Here is a minimalistic example which should hopefully get you started:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Services" %>
<script runat="server">
[WebMethod]
public static string GetRegions(int areaId)
{
return "Foo " + areaId;
}
</script>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>jQuery and page methods</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(function() {
var areaId = 42;
$.ajax({
type: "POST",
url: "Default.aspx/GetRegions",
data: "{areaId:" + areaId + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
alert(data.d);
}
});
});
</script>
</body>
</html>
这篇关于使用jQuery的方法的getJSON与ASP.NET Web窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文