0

我在前端使用 ExtJs,在后端使用 ASP.NET。我对两者都很陌生。我正在尝试使用 ExtJs 向后端发送请求,但是,我收到 404 错误。当我将 URL 从控制台复制到任何浏览器的地址栏时,它工作正常。我使用的是本地主机 URL,所以我不确定这是否是错误。这是我的 ExtJs 代码。(我意识到代码中还有其他一些问题,我现在只希望前端连接到后端)。

ExtJs 代码:

Ext.define('AM.store.Users', {
    extend: 'Ext.data.Store',
    model: 'AM.model.User',
    autoLoad: true,

    proxy: {
        type: 'ajax',
        api: {
            read: 'http://localhost:3849/Home/AmazonRender?numDays=3',
            update: 'data/updateUsers.txt'
        },
        reader: {
            type: 'json',
            root: 'users',
            successProperty: 'success'
        }
    },
    updateUser: function (button) {
        var win = button.up('window'),
    form = win.down('form'),
    record = form.getRecord(),
    values = form.getValues();



    record.set(values);
    win.close();
    this.getUsersStore().sync();
}
});

ASP.NET 代码:

Function amazonRender(ByVal numDays As Integer) As ActionResult
        Dim list As New List(Of Double)()

        Dim bucketName As String = ""
        Dim accessKey As String = ""
        Dim secretKey As String = ""
        ConnectToAmazon(bucketName, accessKey, secretKey)

        Dim client As AmazonS3
        client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKey, secretKey,  RegionEndpoint.USEast1)
        Dim request As ListObjectsRequest = New ListObjectsRequest
        request.BucketName = bucketName
        Dim response As ListObjectsResponse = client.ListObjects(request)
        Dim id As Integer = 1
        Dim responseJsonString As String = "["

        Dim responseList As List(Of String) = New List(Of String)
        For Each s3 As S3Object In response.S3Objects
            responseJsonString = responseJsonString + "{id: " + id.ToString + ", FileName: '" + s3.Key.Trim + "'},"
            id = id + 1
        Next
        responseJsonString = responseJsonString.Substring(0, responseJsonString.Length - 1)
        responseJsonString = responseJsonString + "]"
        Dim serializer As JavaScriptSerializer = New JavaScriptSerializer

        Return Json(New With {Key .success = "true", Key .users = responseJsonString}, JsonRequestBehavior.AllowGet)
    End Function
4

1 回答 1

2

指定 URL 时无需传递完整路径。您可以从 URL 中删除 localhost 和端口号“3849”。如果您使用的是 FireFox,请使用“fire bug”插件。它会告诉你 ExtJS 发布的是什么 URL,你可以将它与实际工作的 url 匹配。在 FireFox 中,您还可以使用一个名为“RESTClient”的插件,它允许您向服务器发送请求,然后您可以检查响应。

于 2013-01-29T04:02:21.330 回答