必学习的前后端交互框架ajax

66 篇文章 3 订阅
31 篇文章 1 订阅

ajax显然是最重要的框架

无论是c#,java,web程序通通能够解决前后端问题。

现在越来越多的人能够开发,为什么?

框架已经改变了程序员,现在基本是个程序员都可以在一个星期内写一个web程序。

ajax让他们更快的上手,mvc框架让他们灵活运用。

ajax替代了以往的servlet,让主界面不用跳转就可以得到不同数据的显示。

ajax有这独特的意义,

ajax如何使用,非常简单,以下步骤就可以学习ajax。

下载ajax.dll

引入项目,

配置web文件

新建ajax.cs文件,注册

html引用和control调用基本事例

function click1() {
        @*location.href = "getresult?xu="+xu;*@
        //$('#cc').append('<h1>fdghhhhhhhhhhhhhh</h1>');
        //var tImg = "<div id='dfggdfgd'>sfrgdfgdfhfghgf</div>";
        // alert();
        $('body').append("<p>sfdgfdfgfdddddddd</p>");
        $('p').remove();
        $.ajax({
            type: 'post',
            url: '@Url.Action("Contact")',
            data: {'xu':'677'},
            contentType: 'application/json;charset=utf-8',
            dataType: 'json',
            success: function (message) {

                alert(message.message);
            }

        });

    }

定义事件,实现ajax传输数据和处理数据

后端

[HttpPost()]
        public ActionResult Contact()
        {
            JsonResult ajaxres = new JsonResult();
            ajaxres.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            //ViewData["xu"] = xu;
            ajaxres.Data = new { message = "徐敬坤" ,data1="67"};
           // String data1 = "67876877778";
            return ajaxres;
        }

这样实现前后端交互

实现这必须要有ajax.dll文件

除了ajax还有form表单,但是处理原理是一致的

<form id="ff" method="post" action="@Url.Action("login1")">
        <center>
            <div class="easyui-panel" style="width:400px;padding:50px 60px">
                <div style="margin-bottom:20px">
                    <input class="easyui-textbox" prompt="Username" iconWidth="28" style="width:100%;height:34px;padding:10px;">
                </div>
                <div style="margin-bottom:20px">
                    <input class="easyui-passwordbox" prompt="Password" iconWidth="28" style="width:100%;height:34px;padding:10px">
                </div>
            </div>
            <input type="submit" value="login" />
            <input type="button" value="register" onclick="click1()" />
        </center>
    </form>

都是通过url.action实现跳转后端。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

人还是要有梦想的

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值