Javascript slim框架和ajax'/';字符作为参数
我正在对slimframeworkweb服务进行ajax调用。这是用来向我的数据库发送注释的 问题是,用户可以编写例如“发送1/2件”。因此,当我进行调用时,URL抛出404未找到,因为“/”字符 有没有办法避免这个问题Javascript slim框架和ajax'/';字符作为参数,javascript,php,ajax,slim,Javascript,Php,Ajax,Slim,我正在对slimframeworkweb服务进行ajax调用。这是用来向我的数据库发送注释的 问题是,用户可以编写例如“发送1/2件”。因此,当我进行调用时,URL抛出404未找到,因为“/”字符 有没有办法避免这个问题 notes = 'send 1/2 piece' $.ajax({ type: 'GET', url: 'http://Myserver/orders/notes/' + MyOrder + '/' + notes,
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){
}
});
您只需要针对notes运行EncodeURIComponent 在调用ajax之前:
notes = 'We have funny characters in here like /es';
encNotes = EncodeURIComponent(notes);
然后,使用编码字符串创建url字符串
url: 'http://Myserver/orders/notes/' + MyOrder + '/' + encNotes,
您只需要针对notes运行EncodeURIComponent 在调用ajax之前:
notes = 'We have funny characters in here like /es';
encNotes = EncodeURIComponent(notes);
然后,使用编码字符串创建url字符串
url: 'http://Myserver/orders/notes/' + MyOrder + '/' + encNotes,
EncodeURI
/EncodeURIComponent
EncodeURIComponent不适合我。它只是对完整的URL进行编码,但我得到的404GET并不是发送任意数据的最佳方法。我会考虑使用POST。<代码> EndoDuri> <代码> />代码> ECOCODURCOMCONMENTRON/<代码> ECOCODUCORCOMCONTCONSONT不适用于我。它只是对完整的URL进行编码,但我得到的404GET并不是发送任意数据的最佳方法。我会考虑使用POST。我得到同样的错误:404(未找到)请在您声明RET Teget的代码中得到相同的错误:404(未找到)请在您声明GET路由的位置发布代码。