通过WebService和jQuery Ajax加载asp页面数据

时间:2018-10-16 06:10:26

标签: jquery asp.net ajax

我已经在asp.net中创建了网页。有些页面使用WebService和jquery ajax从数据库加载数据。我用公共IP在服务器上发布了它。当我在本地浏览器上浏览它时,它工作正常,但是当我从客户端浏览器浏览它时,通过ajax获取的数据不会出现。

<%@ Page Title="" Language="C#" MasterPageFile="~/Main-Page.Master" AutoEventWireup="true" CodeBehind="Pdfs_Page.aspx.cs" Inherits="Information_Technology_Department.Pdfs_Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

        <div class="row">
            <div id="Main_Pdfs_Div" class="co-xs-12">

            </div>
        </div>
    <script src="jquery-1.10.2.min.js"></script>
    <script type="text/javascript">
        var PDFID = '<%=Request.QueryString["PdfId"]%>';
        $.ajax({
            url: '../WebService1.asmx/Get_Pdfs',
            method: 'post',
            dataType: 'json',
            success: function (data) {
                $(data).each(function (index, item) {
                    if(item.Type==1) {
                        $('#Main_Pdfs_Div').append($('<div class="col-xs-12 pdfs_book_view_anchor"><div class="col-xs-12" id="Div' + index + '" ></div><p class="h4 pdfs_book_view_anchor_parograph">' + item.PdfDescription + '  ' + '<a class="Pdf_Content_View_Anchor" href="' + item.PicturePath + '"> عرض</a><br/><hr/></p></div>')
                            .on('click', function () {
                                $('#Div' + index + '').html('');
                                $('#Div' + index + '').append('<img id="Img' + index + '" class=" col-xs-10 img-responsive img-thumbnail" src="' + item.PicturePath + '"/>');
                            })
                            )
                     }
                    else if (item.Type == 0)
                    {
                        $('#Main_Pdfs_Div').append($('<div class="col-xs-12 pdfs_book_view_anchor"><img class="col-xs-3 img-responsive" src="../Images/Pdf_Image.png"/><div class="col-xs-9"><p class="h4 pdfs_book_view_anchor_parograph">' + item.PdfDescription + '  ' + '<a class="Pdf_Content_View_Anchor" href="#"> تنزيل</a><hr/><br/></p></div></div>')
                                .on('click', '.Pdf_Content_View_Anchor', function () {


                                    window.open('../Pdf_Viewer.aspx?PdfId=' + item.PdfId + '', '_self');
                                })
                                )
                    }
                 })
                    $('p.h4').on('mouseenter', function () {
                            $(this).addClass('pdfs_book_view_anchor_Mouse_Hover');
                    })
                        .on('mouseout', function () {
                            $(this).removeClass('pdfs_book_view_anchor_Mouse_Hover');
                })
            },
            error:function(err){
                alert(err);
            }
        })

        $('#Search_BTN').click(function () {
            $.ajax({
                url: '../WebService1.asmx/Search_Get_Pdfs',
                data: { term: $('#Search_Text').val() },
                method: 'post',
                dataType: 'json',
                success: function (data) {
                    $('#Main_Pdfs_Div').html('');
                    $(data).each(function (index, item) {
                        if(item.Type==1) {
                            $('#Main_Pdfs_Div').append($('<div class="col-xs-12 pdfs_book_view_anchor"><div class="col-xs-12" id="Div' + index + '" ></div><p class="h4 pdfs_book_view_anchor_parograph">' + item.PdfDescription + '  ' + '<a class="Pdf_Content_View_Anchor" href="' + item.PicturePath + '"> عرض</a><br/><hr/></p></div>')
                                .on('click', function () {
                                    $('#Div' + index + '').html('');
                                    $('#Div' + index + '').append('<img id="Img' + index + '" class=" col-xs-10 img-responsive img-thumbnail" src="' + item.PicturePath + '"/>');
                                })
                                )
                        }
                        else if (item.Type == 0) {
                            $('#Main_Pdfs_Div').append($('<div class="col-xs-12 pdfs_book_view_anchor"><img class="col-xs-3 img-responsive" src="../Images/Pdf_Image.png"/><div class="col-xs-9"><p class="h4 pdfs_book_view_anchor_parograph">' + item.PdfDescription + '  ' + '<a class="Pdf_Content_View_Anchor" href="#"> تنزيل</a><hr/><br/></p></div></div>')
                                    .on('click', '.Pdf_Content_View_Anchor', function () {
                                      window.open('../Pdf_Viewer.aspx?PdfId=' + item.PdfId + '', '_self');
                                    })
                                    )
                        }
                    })
                    $('#Search_Text').val('');
                },
                error: function (err) {
                    alert(err);
                }
            })
        })
    </script>
</asp:Content>

0 个答案:

没有答案