10 examples of 'jquery post json' in JavaScript

Every line of 'jquery post json' 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.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
24function 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}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

313function _jQueryPost(url, postdata, onsuccess)
314{
315 jQuery.ajax(url, {
316 'type': 'POST',
317 'data': postdata,
318 'dataType': 'json',
319 'success': onsuccess,
320 'error': onAjaxError
321 });
322};
450function postJSON(url, data, callback) {
451 if (arguments.length===2) {
452 callback = data;
453 data = {};
454 }
455 _httpJSON('POST', url, data, callback);
456}
5function postJson(data, url){
6 $.ajax({
7 type: "POST",
8 url: url,
9 data: JSON.stringify(data),// now data come in this function
10 contentType: "application/json; charset=utf-8",
11 crossDomain: true,
12 dataType: "json",
13 success: function (data, status, jqXHR) {
14 bootbox.alert("Applied changes record successfully.");
15 },
16
17 error: function (jqXHR, status) {
18 // error handler
19 console.log(jqXHR);
20 a = jqXHR;
21 bootbox.alert(jqXHR["responseText"]);
22 }
23 });
24 }
5function post(url, data, done) {
6 $.ajax({
7 url: url,
8 type: 'POST',
9 data: data,
10 dataType: 'json',
11 success: function () {
12 done(null);
13 },
14 error: function (xhr, ts, e) {
15 if (xhr && xhr.responseText) {
16 var data = $.parseJSON(xhr.responseText);
17 e = data.errors[0];
18 }
19 done(e);
20 }
21 });
22}
28function postJSON(url, obj, cb) {
29 var req = new XMLHttpRequest()
30 req.onload = function () {
31 cb(null, JSON.parse(req.response))
32 }
33 req.open('POST', url)
34 req.setRequestHeader('Content-Type', 'application/json;charset=UTF-8')
35 setToken(req)
36 req.send(JSON.stringify(obj))
37}
84function _post_json(url,data, success, fail ) {
85 console.log( "----_post--start-------" );
86 wx.request( {
87 url: url,
88 // header: {
89 // 'content-type': 'application/json',
90 // },
91 method:'POST',
92 data:data,
93 success: function( res ) {
94 success( res );
95 },
96 fail: function( res ) {
97 fail( res );
98 }
99 });
100
101 console.log( "----end----_post-----" );
102}
121function ajaxPost(url, data, func) {
122 $.ajax({
123 type: 'POST',
124 url: url,
125 datatype : 'json',
126 async : false,
127 data: data,
128 success: function(ct) {
129 func(ct);
130 }
131 });
132}
25export function apiPostJson(url, body, options = {}) {
26 const csrfToken = options.csrfToken || readCsrfFromPage();
27 return apiFetch(url, {
28 method: 'POST',
29 body: JSON.stringify(body),
30 headers: {
31 'Accept': 'application/json',
32 'Content-Type': 'application/json',
33 'X-CSRF-Token': csrfToken
34 },
35 ...(options.fetchOptions || {})
36 }).then(response => response.json());
37}
8export default function postJSON (url, body) {
9 return window.fetch(url, {
10 method: 'POST',
11 headers: {
12 'Content-Type': 'application/json'
13 },
14 mode: 'cors',
15 body: JSON.stringify(body)
16 })
17}

Related snippets