簡體   English   中英

我們可以調用ajax get方法而不將參數附加到url嗎

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

我知道在get方法中傳遞參數時,它將附加到url上。 有沒有辦法在不附加URL的情況下在get方法中傳遞參數。 例如

 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> 

所以這里的網址是

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

我想要的是 :

http://test.com/

在傳遞post方法時是否可以傳遞參數。

在傳遞post方法時是否可以傳遞參數。

如果您在正文中表示“否”,則因為GET方法不允許正文。 MDN

但是您可以使用標頭,例如$.ajax({ headers: {UserID: "test"}})在這種情況下,您需要修改服務器代碼以從標頭中提取數據。

這是GET方法的功能。

如果您不想將屬性附加到URL,則必須使用POST方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM