jquery ajax调用后台方法,调试发现没有跳转到后台!!!
<script type="text/javascript">$(document).ready(function() {
$("#Butadd").click(function(){
var str=$("#Textforget").val();
$.ajax({
type: "POST",
contentType: "application/json",
url: "MainPage.aspx/AddForget",
data: "{fgstr:str}",
dataType:"json",
success: function(result){
alert(result.d);
}
});
});
});
</script>
对应Default.aspx:
<div class="info">
<textarea id="Textforget" cols="40" rows="2"></textarea>
</div>
<div class="btn">
<input class="butadd" id="Butadd" type="button" value="保存备忘录" />
</div>
对应Default.aspx.cs:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Services;
using System.Web.Script.Services;
public partial class Admin_AdminPage_MainPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string AddForget(string fgstr)
{
int cat=XmlOperation.AddXmlInfo(fgstr, DateTime.Now);
string result;
if (cat > 0)
{
result="保存备忘录成功!";
return result;
}
else
{
result="保存备忘录失败!";
return result;
}
}
}
完整代码贴出来了 希望高手赐教
--------------------编程问答-------------------- 看提交的路径对不对,你可以在firefox 的firebug控制台里面看看 --------------------编程问答-------------------- Admin_AdminPage_MainPage
MainPage.aspx/AddForget 路径不对
../Admin/AdminPage/MainPage.aspx/AddForget 吧。。
--------------------编程问答-------------------- 路径问题 --------------------编程问答-------------------- $.ajax({
type: "POST",
contentType: "application/json",
url: "MainPage.aspx/AddForget",
data: "{fgstr:str}",
dataType:"json",
success: function(rs){
alert(rs.d);
if(rs.success)window.top.loaction="/xxx/xxx.aspx";
}
--------------------编程问答-------------------- 很郁闷,请求的是本页面的后台aspx.cs 路径没错啊
现在是后台方法根本没有执行
高手帮忙啊 --------------------编程问答-------------------- 请求aspx.cs的方法 要求MainPage.aspx里面只保留页面<%@ Page %>这一行。。 --------------------编程问答-------------------- dataType:"text",
contentType: "application/json; charset=utf-8",
补充:.NET技术 , ASP.NET