【发布时间】:2016-12-15 03:20:50
【问题描述】:
我正在对 Slim 框架 Web 服务进行 ajax 调用。这是为了将笔记发送到我的数据库。
问题是用户可以写例如“发送 1/2 件”。因此,当我拨打电话时,由于“/”字符,URL 会抛出 404 not found。
有什么办法可以避免这个问题?
notes = 'send 1/2 piece'
$.ajax({
type: 'GET',
url: 'http://Myserver/orders/notes/' + MyOrder + '/' + notes,
dataType: "json", // data type of response
beforeSend: function(xhr, settings){
},
success: function(data){
},
error: function(xhr, status, errorThrown){
errorPopup(errorThrown);
},
complete: function(xhr, status){
}
});
【问题讨论】:
-
EncodeURI/EncodeURIComponent -
EncodeURIComponent 不适合我。它只是对完整的 URL 进行编码,但我仍然得到 404
-
GET 不是发送任意数据的最佳方法。我会考虑改用 POST。
标签: javascript php ajax slim