问题描述
假设您有一个名为Default.aspx的页面.在此页面上,有一个
Suppose you have a page named Default.aspx. On this page there is a
.您想通过代码文件中的方法在此div中显示日期.
在Default.aspx.cs中,创建如下所示的方法.
添加以下名称空间.
使用System.web.services;
[WebMethod]
公共静态字符串GetData()
{
返回巴基斯坦Zindabad";
}
//将此代码写在Default.aspx头部分.
< script type ="text/javascript" src ="Scripts/jquery-1.4.1.js"></script>
< script type ="text/javascript" src ="Scripts/jquery-1.4.1.min.js"></script>
< script type ="text/javascript">
$(document).ready(function(){
$(#div1").click(function(){
$ .ajax({
类型:"POST",
网址:"default7.aspx/GetData",
数据:"{}",
contentType:"application/json; charset = utf-8",
dataType:"json",
成功:功能(msg){
$(#div1").html(msg.d);
}
});
});
/script>
. You want to show date in this div from a method in code file.
In Default.aspx.cs make a Method like this.
add following namespace.
using System.web.services;
[WebMethod]
public static string GetData()
{
return "Pakistan Zindabad";
}
//write this code on Default.aspx head section.
<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#div1").click(function () {
$.ajax({
type: "POST",
url: "default7.aspx/GetData",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
$("#div1").html(msg.d);
}
});
});
/script>
This solution is working fine.
推荐答案
这篇关于从Jquery Ajax调用调用页面方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!