首页 新闻 会员 周边

htm页面,能够和APSX.CS页面一样写后置代码吗?没有的话有什么办法解决?要实现与数据库交互。

0
悬赏园豆:20 [已解决问题] 解决于 2012-08-08 10:51

htm页面,能够和APSX.CS页面一样写后置代码吗?没有的话有什么办法解决?要实现与数据库交互。

问题补充:

秋风sao落叶的主页 秋风sao落叶 | 初学一级 | 园豆:44
提问于:2012-08-08 10:35
< >
分享
最佳答案
0

在网站中添加ajax wcf数据服务

这是我的Servic.svc

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service
{
public static void InitializeService(DataServiceConfiguration config)
{
// TODO: 设置规则以指明哪些实体集和服务操作是可见的、可更新的,等等。
//示例:
config.UseVerboseErrors = true;
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
config.MaxResultsPerCollection = int.MaxValue;
}
// 要使用 HTTP GET,请添加 [WebGet] 特性。(默认 ResponseFormat 为 WebMessageFormat.Json)
// 要创建返回 XML 的操作,
// 请添加 [WebGet(ResponseFormat=WebMessageFormat.Xml)],
// 并在操作正文中包括以下行:
// WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
[OperationContract]
public void DoWork()
{
// 在此处添加操作实现
return;
}

// 在此处添加更多操作并使用 [OperationContract] 标记它们
[OperationContract]
[WebGet(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public string TestGet()
{
string result = "false";
using (var context = new Entities())
{
var query = (from a in context.T_ZJ_Facility
select a).ToList();
}
return result;
}
[OperationContract]
[WebGet(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public string TestPost(string type,string state,string data)
{
string result = "false";
return result;
}

}

 

前台: 应用jQuery.1.7.1 <script type="text/javascript" src="../Scripts/jquery-1.7.1.min.js"></script>

$("#btnPost").click(function () {
$.ajax({
url: '/Wcf/Service.svc/TestPost',
type: 'POST',
headers: { "Accept": "application/json; odata=verbose", "DataServiceVersion": "3.0", "MaxDataServiceVersion": "3.0"},
data: '{"type":"T_ZJ_Facilty","state":"16",data:"ff"}',
// async: false,
dataType: 'json',
contentType: 'application/json;odata=verbose',
success: function (xhr) {
$.showMessageBox({
msgText: '操作成功',
msgTitle: '提示',
msgBoxType: $.messageBoxType.normal
});
},
error: function (result, status) {
$.showMessageBox({
msgText: result.responseText,
msgTitle: '错误',
msgBoxType: $.messageBoxType.error
});
},
complete: function (xhr, status) {
$.setBusy(false);
}
});
});

收获园豆:20
江南_雾里看花 | 菜鸟二级 |园豆:394 | 2012-08-08 10:46

没用过,, 去试试吧。唉,谢谢了!

秋风sao落叶 | 园豆:44 (初学一级) | 2012-08-08 10:50
其他回答(1)
0

ajax 可以交互啊!

张坤 | 园豆:1865 (小虾三级) | 2012-08-08 10:40

主要还要能实现网页的所有功能,一个系统的。。

支持(0) 反对(0) 秋风sao落叶 | 园豆:44 (初学一级) | 2012-08-08 10:41

@秋风sao落叶:  你的问题比较奇怪, html 只负责 展现数据和提交数据,要实现与数据库交互,必须后端支持啊!

支持(0) 反对(0) 张坤 | 园豆:1865 (小虾三级) | 2012-08-08 10:43

@张坤: 就是想问问,有没有办法实现ASPX.CS这样的文件实现。

支持(0) 反对(0) 秋风sao落叶 | 园豆:44 (初学一级) | 2012-08-08 10:44

@秋风sao落叶:  要想数据库交互,后端代码省不了啊,不用 aspx.cs 你可以用 ashx , 不是一样嘛!

支持(0) 反对(0) 张坤 | 园豆:1865 (小虾三级) | 2012-08-08 10:46
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册