Every line of 'send json data in ajax' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
19 async function sendJson(url, data, type) { 20 return await $.ajax({ 21 url, 22 type, 23 data: JSON.stringify(data), 24 contentType: 'application/json', 25 dataType: 'json' 26 }); 27 }
38 function sendJSONAjaxRequest(isGet, url, requestData, callbackSuccessFunction, callbackErrorFunction){ 39 var argLength = arguments.length; 40 var requestArgumets = arguments; 41 $.ajax({ 42 type:isGet ? "GET" : "POST", 43 url:url, 44 data: requestData, 45 dataType: "json", 46 headers: { 47 "AuthorizationToken": authorizationToken // part of fix for issue #1038, see commonUtils.js 48 }, 49 success: function (responseJSON,code,jqXHR) { 50 //check for page type, if page is login page then show a pop-up for session expire. 51 if (jqXHR.getResponseHeader("loginPage") != null && jqXHR.getResponseHeader("loginPage") == "true") { 52 fnSessionExpireLoginAgain(); 53 return false; 54 } 55 if(responseJSON == null){ 56 fnSessionExpireLoginAgain(); 57 //alert("Response from Server is null."); 58 }else{ 59 var args = []; 60 args.push(responseJSON); 61 62 for(var i = 5; i < argLength; i++){ 63 args.push(requestArgumets[i]); 64 } 65 //Call to success function by passing response and other extra parameter. 66 callbackSuccessFunction.apply(null,args); 67 } 68 }, 69 error: function(errorMessage){ 70 if(callbackErrorFunction != null){ 71 var args = []; 72 args.push(responseJSON); 73 74 for(var i = 5; i < argLength; i++){ 75 args.push(requestArgumets[i]); 76 } 77 callbackErrorFunction.apply(null,args); 78 }else{ 79 fnSessionExpireLoginAgain(); 80 //alert("Error While Serving request. Please try again later."); 81 } 82 } 83 }); 84 }
24 function jsonPost(url, data, callback) { 25 $.ajax({ 26 type : "POST", 27 url : url, 28 dataType : "json", 29 contentType : "application/json", 30 data : JSON.stringify(data), 31 success : callback 32 }); 33 }
412 function _httpJSON(method, url, data, callback) { 413 var opt = { 414 type: method, 415 dataType: 'json' 416 }; 417 if (method==='GET') { 418 opt.url = url + '?' + data; 419 } 420 if (method==='POST') { 421 opt.url = url; 422 opt.data = JSON.stringify(data || {}); 423 opt.contentType = 'application/json'; 424 } 425 $.ajax(opt).done(function (r) { 426 if (r && r.error) { 427 return callback(r); 428 } 429 return callback(null, r); 430 }).fail(function (jqXHR, textStatus) { 431 return callback({'error': 'http_bad_response', 'data': '' + jqXHR.status, 'message': '网络好像出问题了 (HTTP ' + jqXHR.status + ')'}); 432 }); 433 }
450 function postJSON(url, data, callback) { 451 if (arguments.length===2) { 452 callback = data; 453 data = {}; 454 } 455 _httpJSON('POST', url, data, callback); 456 }
21 function send_data(request, data) { 22 data.request = request; 23 document.title = JSON.stringify(data); 24 }
112 function get_json(url, callback) { 113 $.ajax({ 114 url: url, 115 dataType: 'json', 116 success: function(data) { 117 callback(null, data); 118 }, 119 error: function(err) { 120 callback('Error getting: ' + url); 121 } 122 }); 123 }
11 send(action, method, data, callback) { 12 data["action"] = action; 13 14 $.ajax(this.url, { 15 "data": data, 16 "dataType": "json", 17 "headers": {"X-CSRFToken": this.csrf_token}, 18 "method": method, 19 }).done(data => { 20 if ("error_code" in data) { 21 return callback(false, data); 22 } 23 24 return callback(true, data); 25 }).fail(() => callback(false)); 26 }
52 function sendToServer(json){ 53 54 // Draws from http://stackoverflow.com/questions/6418220/javascript-send-json-object-with-ajax 55 var xmlhttp = new XMLHttpRequest(); 56 xmlhttp.open('POST', '/writeDataFlowGraph'); 57 xmlhttp.setRequestHeader('Content-Type', 'application/json;charset=UTF-8'); 58 xmlhttp.send(JSON.stringify(json)); 59 }
118 function send(data) { 119 console.log('send', arguments); 120 121 data.roomId = roomId; 122 data.sender = userId; 123 socket.send(data); 124 }