Javascript (ExtJs) returns a 404 error for a URL, but no problems when I type it into a browser

匆匆过客 提交于 2020-02-07 07:48:26

问题


I am using ExtJs on a front end and an ASP.NET on the back-end. I am pretty new to both. I am trying to send a request to the back end using ExtJs, however, I get a 404 error. When I copy the URL from the console to the address bar in any browser, it works fine. I am using a localhost URL so I am not sure if that is the error. Here is my ExtJs code. (I realize there are some other issues in the code, I just want the front end to connect to the back-end for now).

ExtJs code:

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 code:

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

回答1:


There is no need to pass the full path while specifying the URL. You can remove the localhost and port number '3849' from the URL. If you are using FireFox, use 'fire bug' plugin. It will tell you what URL ExtJS is posting and you can match it with the actual working url. In FireFox you can also use a plugin called 'RESTClient', it will allow you to send request to the server and you can check the response back.



来源:https://stackoverflow.com/questions/13180333/javascript-extjs-returns-a-404-error-for-a-url-but-no-problems-when-i-type-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!