Ajax無重新整理顯示

來源:互聯網
上載者:User

標籤:ace   執行個體   出錯   eth   rip   static   ext   tar   重新整理   

前台頁面

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="QianBao.Dictionary.WebForm1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server">    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    <title>Ajax執行個體1</title>    <script src="js/jquery.js" type="text/javascript"></script>    <script type="text/javascript">        $(function () {            $("#btn1").click(function () {                var txtparam1 = $("#txtParam1").val();                var txtparam2 = $("#txtParam2").val();                $.ajax({                    url: "WebForm1.aspx/AjaxMethod", //發送到本頁面後台AjaxMethod方法                    type: "POST",                    dataType: "json",                    async: true, //async翻譯為非同步,false表示同步,會等待執行完成,true為非同步                    contentType: "application/json; charset=utf-8", //不可少                    data: "{param1:‘" + txtparam1 + "‘,param2:‘" + txtparam2 + "‘}",                    success: function (data) {                        $("#result").html(data.d);                    },                    error: function () {                        alert("請求出錯處理");                    }                });            });        });    </script></head><body>    <form id="form1" runat="server">    參數1:<input type="text" id="txtParam1" value="" /><br />    參數2:<input type="text" id="txtParam2" value="" /><br />    <input type="button" id="btn1" value="提交" /><br />    <div id="result">    </div>    </form></body></html>

後台

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.Services;namespace QianBao.Dictionary{    public partial class WebForm1 : System.Web.UI.Page    {        protected void Page_Load(object sender, EventArgs e)        {        }        //type方式必須是post,方法必須是靜態,方法聲明要加上特性[System.Web.Services.WebMethod()],        //傳遞的參數個數也應該和方法的參數相同。        [System.Web.Services.WebMethod()]        public static string AjaxMethod(string param1, string param2)        {            return "參數1為:" + param1 + ",參數2為:" + param2;        }    }}

 

Ajax無重新整理顯示

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.