javascript 做 cors request 並夾帶 authorization (帳號密碼) 資料給 php
關鍵點在於不論是 XMLHttpRequest 或者是用 ajax,只要有夾帶 authroization (user name & password) 要做認證的話,會多一個 OPTIONS request,而且 javascript 這邊也要做修改。
關鍵點在於不論是 XMLHttpRequest 或者是用 ajax,只要有夾帶 authroization (user name & password) 要做認證的話,會多一個 OPTIONS request,而且 javascript 這邊也要做修改。
起因是因為 iOS 上 safari 瀏覽器在做 ajax request 的時候,有時會有bug (https://stackoverflow.com/questions/33895463/safari-ajax-request-failed-to-load-resource-the-network-connection-was-lost),有個解法是把網頁伺服器的 keep-alive 關閉 reference: https://manage.togglebox.com/index.php?/knowledgebase/article/20/turn-off-keepalive-to-reduce-apache-ram-usage/ https://svennd.be/keepalive-on-or-off-apache-tuning/
Backend C# side string Info = ""; if (ds.Tables[1] != null) { for (int i = 0; i < ds.Tables[1].Rows.Count; i++) { if (Info == "") { } else { Info = Info + ","; } Info = Info + String.Format("{{\"id\": \"{0}\", \"type\": \"{1}\", \"Bal\": \"{2}\"}}", ds.Tables[1].Rows[i]["id"].ToString(), ds.Tables[1].Rows[i]["type"].ToString(), ds.Tables[1].Rows[i]["Bal"].ToString() ); } } Response.Write(String.Format("{{\"username\":\"{0}\", \"credit\":\"{1}\", \"balance\":\"{2}\", […]