廢話不多說,直接上代碼
設置鼠標數去焦點的時候請求后台接口
1 //鼠標失去焦點 2 function onblur2(value,value2){ 3 //debugger; 4 console.log("value",value); 5 console.log("value2",value2); 6 // 發送ajax 7 // (1) 獲取 XMLHttpRequest對象 8 xmlHttp = new XMLHttpRequest(); 9 var array = [ 10 { 11 "id":value2, 12 "sjcc": value 13 } 14 ] 15 console.log("array ",array) 16 // (2) 連接服務器 17 // get 18 //xmlHttp.open("get","/sendAjax/?a=1&b=2"); 19 20 // post 21 xmlHttp.open("post","http://192.168.20.162:2801/honeycomb/U017/updateCgddDetSjcc"); 22 23 // 設置請求頭的Content-Type 24 var ele_csrf=document.getElementsByName("csrfmiddlewaretoken")[0]; 25 xmlHttp.setRequestHeader("Content-Type","application/json"); 26 //xmlHttp.setRequestHeader("X-CSRFToken",ele_csrf.value); 27 28 // (3) 發送數據 29 console.log("array2",array) 30 xmlHttp.send(JSON.stringify(array)) ; // 請求體數據 31 32 33 // (4) 回調函數 success 34 xmlHttp.onreadystatechange = function() { 35 if(this.status==200){ 36 console.log("responseText",this.responseText) 37 38 } 39 }; 40 41 42 }