使用JQUERY解決AJAX的跨域問題

2021-05-24 00:30:06 字數 578 閱讀 2517

使用ajax技術時,跨域問題是個很大的困擾,所幸jquery提供了簡單的方法來解決這個問題。

假設現在有兩台伺服器a.uuplay.com和b.uuplay.com,a服需要在頁面中呼叫b服的介面http://b.uuplay.com/checkuser,來檢測使用者是否存在,可以直接在a服的js中這樣寫:

function checkuser(username)

});伺服器b的後端**如下:

response.setcontenttype("text/html");

response.setheader("cache-control", "no-cache");

printwriter out = response.getwriter();

string result = "0"; //0已註冊,1未註冊

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

if(username!= null && username.trim().length() > 0)else

}jsonobject obj = new jsonobject();

Ajax 使用jQuery 實現Ajax

get post 方式 1 doctype html 2 html lang en 3 head 4 meta charset utf 8 5 title document title 6head 7 script type text j ascript src jquery.js script 8...

jquery的ajax的使用!

1.ajax的使用 以login為例,ajax表單的提交!以下是表單 提交的js controller層 基於spring mvc 接收資料和改變資料 controller public class usercontroller public string tologinui 2.get和 post...

jQuery中ajax的使用

ajax get post url 必寫的 表示要傳送的目標位址data 可選的 表示要傳送的資料success 可選的 傳送請求成功後的 datatype 可選的 表示以什麼樣的方式來處理響應回來的資料 form serialize 為什麼要使用模板引擎 基本使用步驟 引入模板檔案 準備模板 呼叫...