加载网页没有回复使用asp.net和ajax无法正常工作?

时间:2016-10-29 12:36:36

标签: javascript jquery html asp.net ajax

总结一下我要做的事情,我在我的网站上创建了两个表单,当用户点击下一个或上一个按钮时,它应该从一个表单转换到另一个表单而不回发。但问题是,当我点击下一步时,它什么也没做。我已经在我的ajax代码中定位了相应的id和url,但它仍然无效。截至目前,我正在使用ajax用于那些非post post,我的网站是用asp.net构建的。希望你们能帮助我解决这个问题。

以下是ajax(loader.js)的代码:

$(document).ready(function () {
$.ajaxSetup({
    cache: false,
    dataType: "aspx",
    error: function (xhr, status, error) {
        alert('An error occured:' + error);
    },
    timeout: 30000,
    type: "GET",
    beforeSend: function () {
        console.log('In Ajax complete function');
    }
});
$("#btnNext").click(function (e) {
    e.preventDefault();
    $.ajax({
        url: "Pages/CreateNewItems2.aspx",
        success: function (data) {
            $("#ContentPlaceHolder1").aspx("").append(data);
        }
    });
});
});

这是我网站的主页:

  <%@ Master Language="C#" AutoEventWireup="true"    CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

  <!DOCTYPE html>

   <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">

   <script src="../Javascript/jquery-1.11.2.min.js"></script>
   <script src="../Javascript/loader.js"></script>

   <link rel="stylesheet" href="~/Styles/jquery.bxslider.css"/>
   <link rel="stylesheet" href="~/Styles/StyleSheet.css"/>
   <link rel="stylesheet" href="~/Styles/font-awesome.min.css"/>
   <link rel="shortcut icon" type="image/png" href="~/Images/rockSign.png"/>

    <style type="text/css">
    .auto-style2 {
        height: 298px;
    }
   </style>

   </head>
   <body>
    <form id="form1" runat="server">
    <div id="wrapper">
        <header id="main_header">
            <div id="callout">
                <h2>&#9742; 111222333</h2>
                <p>Michigan State Kawasaki Iceland</p>
            </div>
            <h1>MUSIC STORE</h1>
        </header>

        <div class="clearfix"></div>

        <nav id="nav_menu">
            <ul id="nav">
                <li><a href="~/Pages/Home.aspx" runat="server">HOME</a></li>
                <li><a href="#">INSTRUMENTS</a>
                    <ul class="sub-menu">
                        <li><a href="~/Pages/GuitarBrands.aspx" runat="server">ELECTRIC GUITARS</a></li>
                        <li><a href="#">BASS GUITARS</a></li>
                        <li><a href="#">DRUMS</a></li>
                    </ul>
                </li>
                <li><a href="#">AMPLIFIERS</a></li>
                <li><a href="#">ACCESSORIES</a></li>
                <li><a href="#">FEATURED ARTISTS</a></li>
                <li><a href="#"><img src="../Images/cog.png" /></a>
                    <ul class="cog_submenu">
                        <li><a href="~/Pages/NewBrands.aspx" runat="server">CREATE NEW BRAND</a></li>
                        <li><a href="#">USE EXISTING BRAND</a></li>
                        <li><a href="~/Pages/OverviewData.aspx" runat="server">DATA OVERVIEW</a></li>
                    </ul>
               </li>
       </ul>
        </nav>



        <div id="content_area">




            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
            </asp:ContentPlaceHolder>



        </div>
        <div class="clearfix"></div>

        <footer>
            <p>&copy;All Rights Reserved</p>
        </footer>
    </div>
</form>
 </body>
 </html>

这是第一个表单的代码,它有下一个按钮:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPageCMS.master" AutoEventWireup="true" CodeFile="NewBrands.aspx.cs" Inherits="Pages_NewBrands" %>

 <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <h3>Create New Brand(Step 1 of 2):</h3>
<table cellspacing="15" class="brandsTable">
    <tr>
        <td style="width: 160px; height: 37px;">

            <strong>Brand Type:</strong></td>

        <td style="height: 37px">

            <asp:TextBox ID="brandType" runat="server" BackColor="#FFFF66" BorderColor="Black" BorderWidth="1px" Height="20px" Width="300px"></asp:TextBox>

        </td>
    </tr>

    <tr>
        <td style="width: 160px; height: 37px;">

            <strong>Brand Name:</strong></td>

        <td style="height: 37px">

            <asp:TextBox ID="brandName" runat="server" BackColor="#FFFF66" BorderColor="Black" BorderWidth="1px" Height="20px" Width="300px"></asp:TextBox>

        </td>
    </tr>

    <tr>
        <td style="width: 160px">

            <strong>Brand Image:</strong></td>

        <td>

            <asp:DropDownList ID="brandImage" runat="server" Width="300px">
            </asp:DropDownList>
            <br />
            <asp:FileUpload ID="brandFileUpload" runat="server" />
            <asp:Button ID="brandUploadImage" runat="server" Text="Upload Image" OnClick="brandUploadImage_Click" />
        </td>
    </tr>




</table>

<asp:Label ID="lblResult" runat="server" Text=""></asp:Label>
<br />
<asp:Button ID="btnNext" runat="server" Text="Next" />
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" />


 </asp:Content>

对于第二种形式,我不会在此处包含代码,因为它没有必要。第二个表单的名称是CreateNewItems2.aspx,它位于我的Pages文件夹中。

0 个答案:

没有答案