簡單的實現jsonp跨域請求
標籤:jsonp
後續再進行詳細補充
java後臺程式碼
/**
* pingan_sap jsonp呼叫,初始化上線後的 服務違禁用語
* @param response
* @param workgroupid
* @param subccno
* @param vdn
* @param callback
*/
@RequestMapping(value = "/keywordServiceDisableGrid",method = {RequestMethod.GET })
@ResponseBody
public void keywordServiceDisableGrid(HttpServletResponse response, String workgroupid, String subccno, String vdn, String callback) {
JSONObject retJsonObject=new JSONObject();
try{
boolean flag = ctiService.getServiceDisableDataGrid(workgroupid, subccno, vdn);
if (flag) {
retJsonObject.put("resultcode", "0");
retJsonObject.put("resultmsg", "success");
}else{
retJsonObject.put("resultcode", "1");
retJsonObject.put("resultmsg", "failure");
}
log.error("更新違禁用語,呼叫結果 = " + flag);
}catch(Exception e){
retJsonObject.put("resultcode", "1");
retJsonObject.put("resultmsg", "failure");
log.error(e.getMessage());
}
// 接收引數callback名稱需要與js中配置的jsonp標籤名一致
String result = callback+"("+retJsonObject.toString()+");";//拼接可執行的js
//返回客戶端內容
PrintWriter pw= null;
try {
pw = response.getWriter();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(result);
pw.print(result);
}
js前端程式碼
<!-- 上線匯入的服務禁用語,跨域請求cti -->
function onlineKeyword(){
$.ajax({
type : 'GET',
dataType : 'jsonp', // 資料型別配置成jsonp
jsonp : "callback", //配置jsonp隨機碼標籤,在伺服器程式碼部分需要用到他來拼接一個json的js物件
url : 'http://127.0.0.1:8081/pingan_cti/interfaces/keywordServiceDisableGrid', //服務路徑
async : false,
data: {
"workgroupid":'-1',
"subccno":'1',
"vdn":'1',
},
success : function (response) {
if(response.resultcode == 0){
Modal_Alert('服務禁用語管理','上線成功');
}else{
Modal_Alert('服務禁用語管理','上線失敗');
}
},
error: function (XMLHttpReuqest, textStautus, errothrown) {
console.log(XMLHttpRequest.status);
console.log(XMLHttpReuqest.readyState);
console.log(XMLHttpRequest.responseText);
console.log(textStautus);
console.log(errothrown);
Modal_Alert('服務禁用語管理','上線失敗');
}
});
}
jsp
<button type="button" class="btn btn-info btn-sm" onclick="onlineKeyword()"><span class="ace-icon fa glyphicon-plus icon-on-right bigger-110"></span>上線</button>
相關文章
- PHP AJAX JSONP實現跨域請求使用例項PHPJSON跨域
- 利用JQuery實現更簡單的Ajax跨域請求jQuery跨域
- php 支援jsonp跨域請求PHPJSON跨域
- js便籤筆記(13)——jsonp其實很簡單【ajax跨域請求】筆記JSON跨域
- 利用Jsonp實現跨域請求,spring MVC+JQueryJSON跨域SpringMVCjQuery
- JSONP解決跨域請求問題JSON跨域
- ajax跨域請求簡單介紹跨域
- ajax實現跨域請求程式碼例項簡單介紹跨域
- 跨域請求之jQuery的ajax jsonp的使用解惑跨域jQueryJSON
- 搞定所有的跨域請求問題: jsonp & CORS跨域JSONCORS
- 中止請求和超時 跨域的HTTP請求 認證方式 JSONP跨域HTTPJSON
- JSONP 跨域原理及實現JSON跨域
- 跨域請求?兩種解決方案CORS與JSONP跨域CORSJSON
- Ajax+SpringMVC實現跨域請求SpringMVC跨域
- ajax跨域post請求,如何實現呢跨域
- 跨域請求跨域
- ajax實現的跨域請求程式碼例項跨域
- JSONP原理及實現跨域方式JSON跨域
- CORS跨域請求CORS跨域
- vue跨域請求Vue跨域
- jquery 之 jsonp 與 laravel 實現跨域jQueryJSONLaravel跨域
- $.getJSON()實現跨域請求程式碼例項JSON跨域
- 前端跨域請求原理及實踐前端跨域
- jquery ajax 跨域請求jQuery跨域
- 巧用javascript ajax,實現跨域請求外帶,增大漏洞危害JavaScript跨域
- ajax jsonp跨域JSON跨域
- springboot系列文章之實現跨域請求(CORS)Spring Boot跨域CORS
- 同源政策與跨域請求跨域
- 跨域請求後端配置跨域後端
- Vue——介面請求支援跨域Vue跨域
- vue axios 請求跨域VueiOS跨域
- NGINX如何配置跨域請求Nginx跨域
- 什麼是跨域請求?跨域
- CORS跨域請求總結CORS跨域
- 使用CORS實現ajax跨域簡單介紹CORS跨域
- 輕量級網站建設jsonp跨域簡單例項網站JSON跨域單例
- ajax跨域請求之CORS的使用跨域CORS
- Flutter 網路請求的三種簡單實現Flutter