當前位置:編程學習大全網 - 編程軟體 - 修改網頁源碼VC 編程實現在本地修改網頁源代碼,同時保證POST提交數據有效

修改網頁源碼VC 編程實現在本地修改網頁源代碼,同時保證POST提交數據有效

壹般情況下,使用Ajax提交的參數多是些簡單的字符串,可以直接使用GET方法將要提交的參數寫到open方法的url參數中,此時send方法的參數為null。例如 :!--[if !supportLists]-->1 !--[endif]-->var url = login.jsp?user=XXX&pwd=XXX;!--[if !supportLists]-->2 !--[endif]-->xmlHttpRequest.open(GET,url,true);!--[if !supportLists]-->3 !--[endif]-->xmlHttpRequset.send(null);

此外,也可以使用send方法傳遞參數。使用send方法傳遞參數使用的是POST方法,需要設定Content-Type頭信息,模擬HTTP POST方法發送壹個表單,這樣服務器才會知道如何處理上傳的內容。參數的提交格式和GET方法中url的寫法壹樣。設置頭信息前必須先調用open方 法。 例如:!--[if !supportLists]-->1 !--[endif]-->xmlHttpRequest.open(POST,login.jsp,true);!--[if !supportLists]-->2 !--[endif]-->xmlHttpRequest.setRequestHeder(Content-Type,application/x--form-urlencoded;charset=UTF-8);!--[if !supportLists]-->3 !--[endif]-->xmlHttpRequest.send(user=+username+&pwd=+password);

需要註意的是根據提交方式的不同,兩種提交方式分別調用後臺的doGet方法和doPost方法。

  • 上一篇:學習機器人編程需要先學哪些課程?我可以從機器人編程中學習到什麽?
  • 下一篇:求助win 7 cmd壹閃而過這個問題怎麽解決
  • copyright 2024編程學習大全網