使用AJAX中的get請求中文亂碼的問題

2021-09-28 11:11:15 字數 1126 閱讀 7369

get請求中文亂碼

post請求沒有中文亂碼

前端js獲取表單內容的**:

var username = document.getelementbyid("username").value;

var password = document.getelementbyid("password").value;

後端獲取ajax傳過來的資料的**:

string username = req.getparameter("username");

string password = req.getparameter("password");

修改後前端獲取表單內容的**為:

js檔案中使用encodeuri()方法兩次。

var username = encodeuri(encodeuri(document.getelementbyid("username").value));

var password = encodeuri(encodeuri(document.getelementbyid("password").value));

修改後後端獲取ajax傳過來的資料的**為:

在後台中對傳遞的引數進行urldecoder解碼。

Ajax中get請求和post請求

我們在使用ajax向伺服器傳送資料時,可以採用get方式請求伺服器,也可以使用post方式請求伺服器,那麼什麼時候該採用get方式,什麼時候該採用post方式呢?get請求和post請求的區別 1.使用get請求時,請求所帶的引數會跟在url後傳遞,而post請求則是作為http訊息的實體內容傳送給...

Ajax中Get請求與Post請求的區別

我們在使用ajax時,當我們向伺服器傳送資料時,我們可以採用get方式請求伺服器,也可以使用post方式請求伺服器.那麼,我們什麼時候該採用get方式,什麼時候該採用post方式呢?get請求和post請求的區別 1.使用get請求時,引數在url中顯示,而使用post方式,則不會顯示出來 2.使用...

Ajax請求中post和get的區別

http請求3個組成部分與xmlhttprequest方法的對應關係 1 請求行 2 請求頭 get 請求可以不設定 3 請求主體 建立乙個非同步 設定請求行 open 請求方法,請求url get請求如果有引數就需要在url後面拼接引數 post請求在請求體中傳遞 xhr.open get ind...