简体   繁体   中英

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. Is there any way to pass the parameters in get method without appending to URL. 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

What I want :

http://test.com/

Is it possible to pass the parameters as we pass in post method.

Is it possible to pass the parameters as we pass in post method.

If you mean in body then no, because GET method does not allow body. 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.

This is the feature of GET method.

If you don't want to append the properties to URL, must be use POST method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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