简体   繁体   English

Ajax调用的REST URL参数中的“ /”问题

[英]problem with '/' in the REST URL parameters for an Ajax call

var url     = relativeURI+'/rest/PPS/Prod/'+encodeURIComponent(prod)+'/Section/'+encodeURIComponent(section);

$j.ajax({
  url: url,

  type: 'POST',

  error: function(){
    alert('Error');
  },
  success: function(){
   alert('ItWorks');
  }
});

}

In this ajax call, if I have '/' in the parameters prod or sec, then there is an error. 在此ajax调用中,如果我在prod或sec参数中包含“ /”,则将出现错误。 The request does not even hit the server. 该请求甚至没有到达服务器。 I am using the encodeURIComponent over the parameters. 我在参数上使用encodeURIComponent。 It works fine for other parameters that do not have '/' in them. 对于其他没有'/'的参数,它也可以正常工作。 Please help. 请帮忙。

I replicated your logic and the request does go to the server. 我复制了您的逻辑,请求确实到达了服务器。 However, if the server doesn't like the URL, then your server side code won't even get called. 但是,如果服务器不喜欢该URL,那么您的服务器端代码甚至都不会被调用。 (In my case, there was no server side code, but I can see the 404 response and can see that the server -- Apache -- decoded the URL). (在我的情况下,没有服务器端代码,但是我可以看到404响应,并且可以看到服务器-Apache-解码了URL)。

So perhaps your server can't decode the URL. 因此,也许您的服务器无法解码URL。 Are you sure that you encoded it when you tried the non-jquery route? 您确定在尝试非jquery路由时对它进行了编码吗? You might not need the encodeURIComponent calls. 您可能不需要encodeURIComponent调用。 What happens if you remove them? 如果删除它们会怎样?

I have encoded the parameters and tried the non-jQuery route where it works fine ( Was using RESTEasy). 我已经对参数进行了编码,并尝试了在非jQuery路由上正常运行的方法(正在使用RESTEasy)。 When i remove the slashes, then I get 404 response, which means that there is no REST method with that URI. 当我删除斜杠时,我得到404响应,这意味着该URI没有REST方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM