ASP.net只加载数据onload而不是页面HTML

时间:2015-03-18 13:43:00

标签: javascript html asp.net ajax vb.net

我遇到了一些问题,只是想在没有所有HTML加载的情况下将一些数据输出到页面。我正在使用AJAX调用相同的ASPX页面,以便填充一些数据以返回到AJAX调用。但是,它当前确实调用并且确实填充了正确的数据 但是它似乎不想将该数据放到页面上。

目前在加载页面时出错“此网页不可用:ERR_CONNECTION_RESET”

当我像这样加载页面时:

http://localhost:2765/Default.aspx?Data=viewData

是我收到错误的“此网页不可用:ERR_CONNECTION_RESET”。放入一些代码中断,我可以确认它确实填充了所需的数据,但似乎从未在页面上显示它,并且它似乎在最终停止之前至少调用了2次页面(可能导致上述错误)。

default.aspx代码是:

 <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="default.aspx.vb" Inherits="AdminPanel._default" %>
 <% If loadHTMLPage Then %>
   <!DOCTYPE html>

   <html xmlns="http://www.w3.org/1999/xhtml">
   <head runat="server">
     <meta charset="utf-8" />
     ....[more HTML code here]....
  <script type="text/javascript">
    $(document).ready(function () {
        var clickedButtonName = "";

        $('#dashboardData, #viewData, #updateData, #addData, #deleteData').click(function() {
            clickedButtonName = '#' + $(this).attr("id");

            $.ajax({
                url: $(this).attr("id") + ".aspx",
                dataType: 'html',
                timeout: 10000,
                success: function (html) {
                    $("#jQueryLoadHere").html(html);
                    $('#dashName').html("<strong>" + $(clickedButtonName).data("title") + "</strong> Page");
                    $('#dashboardData_LI, #viewData_LI, #updateData_LI, #addData_LI, #deleteData_LI').attr('class', 'nav-parent');
                    $(clickedButtonName + '_LI').attr('class', 'nav-parent nav-active active');
                }
            });
        });
     });
     </script>
    </form>
  </body>
  </html>
 <% Else %>
 <% =pageData %>
 <% End If %>

代码隐藏是这样的:

Public Class _default
   Inherits System.Web.UI.Page
   Dim whatData As String = Nothing
   Public loadHTMLPage As Boolean = True

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    whatData = Request.QueryString("Data")

    Response.Write(whatData)

    If whatData = "viewData" And hasLoaded = False Then
        loadHTMLPage = False
        hasLoaded = True
        Call workingGetFEBList()
    End If
End Sub

Private Sub workingGetFEBList()
    Dim request As WebRequest = WebRequest.Create(apiURL & appID & "/" & formID & "?format=text/xml")

    request.Method = "GET"
    request.Credentials = CredentialCache.DefaultCredentials

    Dim response1 As WebResponse = request.GetResponse()
    Dim dataStream As Stream = response1.GetResponseStream()
    Dim reader As New StreamReader(dataStream)
    Dim serverResponse As String = reader.ReadToEnd()

    reader.Close()
    dataStream.Close()
    Response.Close()

    Dim theOutput As String = parseXML2JSON(serverResponse)

    pageData = theOutput
End Sub

如果我发表评论:

Call workingGetFEBList()
pageData = theOutput

并刷新页面 - 它可以正常加载页面(空白页面上只有 viewData 文本)。

同样,只需加载页面:

http://localhost:2765/Default.aspx

使用普通的HTML加载页面就好了。

那么我还能错过什么?

0 个答案:

没有答案