我在前端使用 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