简体   繁体   English

我们可以调用ajax get方法而不将参数附加到url吗

[英]Can we call ajax get method without appending parameters to url

I know that when pass parameters in get method, it will be appended to url. 我知道在get方法中传递参数时,它将附加到url上。 Is there any way to pass the parameters in get method without appending to URL. 有没有办法在不附加URL的情况下在get方法中传递参数。 eg 例如

 function ajaxgetCall() { $.ajax({ url: "http://test.com", type: "get", //send it through get method data: { UserID: "test", EmailAddress: "test@test.test" }, success: function(response) { console.log("Sucess"); }, error: function(xhr) { console.log("Error"); } }); }; ajaxgetCall(); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> 

So here url would be, 所以这里的网址是

http://test.com/?UserID=test&EmailAddress=test%40test.test http://test.com/?UserID=test&EmailAddress=test%40test.test

What I want : 我想要的是 :

http://test.com/ http://test.com/

Is it possible to pass the parameters as we pass in post method. 在传递post方法时是否可以传递参数。

Is it possible to pass the parameters as we pass in post method. 在传递post方法时是否可以传递参数。

If you mean in body then no, because GET method does not allow body. 如果您在正文中表示“否”,则因为GET方法不允许正文。 MDN MDN

But you could use headers for example $.ajax({ headers: {UserID: "test"}}) In that case you'd need to modify your server code to extract data from headers. 但是您可以使用标头,例如$.ajax({ headers: {UserID: "test"}})在这种情况下,您需要修改服务器代码以从标头中提取数据。

This is the feature of GET method. 这是GET方法的功能。

If you don't want to append the properties to URL, must be use POST method. 如果您不想将属性附加到URL,则必须使用POST方法。

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

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