使用ajax怎样把前台得到的URL传递到后台,求代码(新手)

harbour_bin 2013-08-08 06:33:54
前台
    
<script src="js/jquery-1.4.2.min.js"type="text/javascript"></script>
<script type="text/javascript" language="javascript">
alert(window.location);
function testAjax() {
$.post('Default4.aspx',{ url:window.location.href },function (text, status) { alert(text); });
}
</script>


后台:
Response.Write(Request["url"].ToString());
...全文
290 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
后台 string action = RmsRequest.GetString("act" ); switch (action.ToLower()) { case "dropmap" : AjaxDeleteSelectMap( RmsRequest.GetInt("id" , 0)); break; case "getsectionpoint" : GetSectionPoint( RmsRequest.GetInt("id" , 0)); break; } 这里说明下 这段代码是放在page load里面 ajax请求会触发这个事件,在里面开始执行ajax的后台逻辑部分
  • 打赏
  • 举报
回复
楼主你这样理解 ajax就是发出了一个请求 后面带一些参数 同时postback为true
$.ajax({
                    type: "POST",// 使用get方法访问后台
                    url: "SaveEigenMedia.aspx",
                    data: "act=GetSectionPoint&id=" + $("#txtColumnSectionID" ).val(),
                    success: function(msg) {
                       //msg就是response写入的信息
                        }
                    
                });

后台

 string action = RmsRequest.GetString("act" );
            switch (action.ToLower())
            {
                case "dropmap" :
                    AjaxDeleteSelectMap( RmsRequest.GetInt("id" , 0));
                    break;
           
                case  "getsectionpoint" :
                    GetSectionPoint( RmsRequest.GetInt("id" , 0));
                    break;
                   
            }

 private void GetSectionPoint(int SectionID)
        {
            Response.Clear();
            string secId = SectionID + "" ;
            if (points == null )
            {
                points = GetPointsInit();
            }
            if (points.ContainsKey(secId))
            {
                 Response.Write(points[secId].PointX + "#" +                                   
                                 points[secId].PointY);
            }
            Response.End();
        }
wonder_zs 2013-08-08
  • 打赏
  • 举报
回复
webform还是?mvc? webform的话比如放置一个hide的input,<input id="myControl" type="hide" />这样的,然后在后台直接用就可以了,myControl.Value mvc的话,在controller中使用就可以了

        public ActionResult Address(string address)
        {
            Return address;
        }
$.post('Default4.aspx',address,function{}());这样就可以了
harbour_bin 2013-08-08
  • 打赏
  • 举报
回复
额,能详细点?
  • 打赏
  • 举报
回复
用ashx一般处理程序
harbour_bin 2013-08-08
  • 打赏
  • 举报
回复
求大神解答。

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧