我在前端使用ExtJs,在后端使用ASP.NET。我对两者都很陌生。我试图使用ExtJs向后端发送请求,但是,我收到404错误。当我在任何浏览器中将URL从控制台复制到地址栏时,它可以正常工作。我正在使用localhost 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
答案 0 :(得分:2)
指定URL时无需传递完整路径。您可以从URL中删除localhost和端口号“3849”。如果您使用的是FireFox,请使用“fire bug”插件。它将告诉您ExtJS发布的URL,您可以将其与实际工作URL匹配。在FireFox中,您还可以使用名为“RESTClient”的插件,它允许您向服务器发送请求,然后您可以检查响应。