$ .ajax调用不是从devextreme触发

时间:2015-09-13 20:22:09

标签: ajax devextreme

我有一个像这样创建的服务。

service.vb

_ 公共类伞形服务     继承System.Web.Services.WebService     实现IUmbrellaMobileService

Function GetCustomers() As List(Of Customers) Implements IUmbrellaMobileService.GetCustomers

    Try
        Dim Cust As List(Of Customers) = New List(Of Customers)

        Dim SQLSTR As String = ""
        SQLSTR = "Select Companies.Code, Companies.Name FROM Companies WHERE ISCustomer = '1'"

        Dim ErrorMessage As String = ""
        ErrorMessage = UmbrellaDataManagementObj.OpenConnection(SQLServer, UmbrellaDatabase, UserCode, UserPassword)
        If ErrorMessage <> "" Then
            System.Diagnostics.EventLog.WriteEntry("Umbrella Mobile Service", ErrorMessage & vbNewLine & UmbrellaDataManagementObj.ConnectionString, EventLogEntryType.Error)
            WebOperationContext.Current.OutgoingResponse.StatusCode = 501
            WebOperationContext.Current.OutgoingResponse.StatusDescription = ErrorMessage


            Return Nothing
        Else
            Dim CustomerDetails As DataSet
            CustomerDetails = UmbrellaDataManagementObj.GetDataSQL(SQLSTR)
            If Not CustomerDetails Is Nothing Then
                CustomerDetails.DataSetName = "Companies"
                CustomerDetails.Tables(0).TableName = "Companies"
                Dim CustomerTable As DataTable
                Dim CustomerRow As DataRow

                If CustomerDetails.Tables.Count > 0 Then
                    CustomerTable = CustomerDetails.Tables(0)
                    If CustomerTable.Rows.Count > 0 Then

                        Dim i As Integer

                        For i = 0 To CustomerTable.Rows.Count - 1
                            CustomerRow = CustomerTable.Rows(i)
                            Dim CC As New Customers
                            CC.Code = CustomerRow.Item("Code")
                            CC.Name = CustomerRow.Item("Name")

                            Cust.Add(CC)


                        Next i
                        ' Serialize the results as JSON
                        Dim serializer As DataContractJsonSerializer = New DataContractJsonSerializer(Cust.GetType())
                        Dim Stream As MemoryStream = New MemoryStream

                        serializer.WriteObject(Stream, Cust)

                        ' Return the results serialized as JSON
                        Dim json As String = Encoding.Default.GetString(Stream.ToArray())
                        '  Return json
                        Return Cust
                        UmbrellaDataManagementObj.CloseConnection()
                        WebOperationContext.Current.OutgoingResponse.StatusCode = 200
                        WebOperationContext.Current.OutgoingResponse.StatusDescription = "OK"
                    End If
                End If



                'Return Cust
            Else
                System.Diagnostics.EventLog.WriteEntry("Umbrella Mobile Service", UmbrellaDataManagementObj.ErrorMessage, EventLogEntryType.Error)

                WebOperationContext.Current.OutgoingResponse.StatusCode = 501
                WebOperationContext.Current.OutgoingResponse.StatusDescription = UmbrellaDataManagementObj.ErrorMessage

                Cust = Nothing
                Return Nothing
            End If
        End If



    Catch ex As Exception
        System.Diagnostics.EventLog.WriteEntry("Umbrella Mobile Service", ex.Message, EventLogEntryType.Error)

        WebOperationContext.Current.OutgoingResponse.StatusCode = 501
        WebOperationContext.Current.OutgoingResponse.StatusDescription = ex.Message


        Return Nothing
    End Try
    Dispose()
End Function

界面如下所示:

<ServiceContract()> _
Public Interface IUmbrellaMobileService


    <OperationContract()> _
       <WebInvoke(Method:="GET", BodyStyle:=WebMessageBodyStyle.Bare, ResponseFormat:=WebMessageFormat.Json)> _
    Function GetCustomers() As List(Of Customers)

End Interface

我的Datacontract看起来像:

<DataContract()> _
Public Class Customers
    Dim CompanyName As String
    Dim CompanyCode As String


    <DataMember()> _
    Public Property Name() As String
        Get
            Return CompanyName
        End Get
        Set(ByVal value As String)
            CompanyName = value
        End Set
    End Property

    <DataMember()> _
    Public Property Code() As String
        Get
            Return CompanyCode
        End Get
        Set(ByVal value As String)
            CompanyCode = value
        End Set
    End Property
End Class

现在,当我输入地址http://agilesoft.dyndns.org/UmbrellaMobileService/GetCustomers时,我得到了如下返回的JSON数组:

[{“Code”:“001”,“Name”:“rainbow”},{“Code”:“009MAY”,“Name”:“A M G AUDIO:HIRE ACC。”}]

我正在尝试在Devextreme应用程序中显示此信息。这是我的dxview的代码:

<div data-options="dxView : { name: 'Customer', title: 'Customer' } " >
    <div  data-options="dxContent : { targetPlaceholder: 'content' } " >

               <div data-bind="dxList: { items: listItems }">
            <div data-options="dxTemplate: { name: 'item' } ">
                <div data-bind="text: Name"></div>
            </div>
        </div>          
        </div>
</div>

这是js文件的代码:

UmbrellaMobile.Customer = function (params) {

    var baseAddress = 'http://agilesoft.dyndns.org/UmbrellaMobileService/GetCustomers';
    var listItems;
    var viewModel = {
        Customers: new DevExpress.data.CustomStore({
            load: function () {
                return $.ajax({
                    url: baseAddress,
                    crossOrigin: true,
                    jsonp: true,
                    type: 'GET',
                    data: '{}',
                    dataType: 'jsonp',
                    contentType: "application/json; charset=utf-8",
                    success: function (res) {
                        listItems: data;
                        console.log("success");
                    },
                    error: function (res) {
                        console.log("error");
                    }
                });
            }
        })

    };

    return {
        listItems: listItems,
        viewModel: viewModel
    };
};

当我在Firefox中运行此应用程序时,收到一条消息“无数据显示”

我试过调试代码。我已设置断点并查看控制台窗口以获取任何提示。我没有得到任何错误。 ajax调用永远不会被执行,或者它似乎永远不会被击中

我只是想显示信息

任何人都可以帮忙看看问题是什么吗?

0 个答案:

没有答案