10 examples of 'jquery post form data' in JavaScript

Every line of 'jquery post form data' 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
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};
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

270function PostData(method,postdata){
271 var token = $("input[name=csrfmiddlewaretoken]").val();
272 postData = JSON.stringify(postdata);
273
274 $.ajax({
275 type: "post",
276 url: "/dashboard/vsm/devices-management/"+method+"/",
277 data: postData,
278 dataType:"json",
279 success: function(data){
280 switch(method){
281 case "get_available_disks":
282 UpdatePopoverForm(data);
283 break;
284 case "check_device_path":
285 if(data.status == "OK"){
286 //After check the path,then add the osd model into the table
287 AddOSDItemInTable();
288 }
289 else{
290 showTip("error",data.message);
291 }
292 break;
293 case "add_new_osd_action":
294 if(data.status == "OK"){
295 window.location.href = "/dashboard/vsm/devices-management/";
296 }
297 else{
298 showTip("error",data.message);
299 }
300 break;
301 }
302 },
303 error: function (XMLHttpRequest, textStatus, errorThrown) {
304 if(XMLHttpRequest.status == 500){
305 showTip("error","Internal Error");
306 }
307 },
308 headers: {
309 "X-CSRFToken": token
310 },
311 complete: function(){
312
313 }
314 });
315}
61function postForm($form, callback) {
62 var values = {};
63 $.each($form.serializeArray(), function(i, field) {
64 values[field.name] = field.value;
65 });
66
67 $.post($form.attr('action'), values)
68 .done(function(data) {
69 callback(data);
70 })
71 .fail(function() {
72 generalError;
73 });
74}
2function formPostData(url, fields) {
3 var form = $('<form style="display: none;" method="post" action="' + url + '"></form>');
4 $.each(fields, function(name, value) {
5 var input = $('<input type="hidden" name="' + name + '">');
6 input.attr('value', value);
7 form.append(input);
8 });
9
10 $(document).find('body').append(form);
11
12 form[0].submit(function(e) {
13 e.preventDefault();
14 });
15
16 form.remove();
17}
804function postData() {
805 $("#comment-container").load("/comments",{
806 "parentComment.id" : $("[name='parentComment.id']").val(),
807 "blog.id" : $("[name='blog.id']").val(),
808 "nickname": $("[name='nickname']").val(),
809 "email" : $("[name='email']").val(),
810 "content" : $("[name='content']").val()
811 },function (responseTxt, statusTxt, xhr) {
812 clearContent();
813 });
814}
33function postForm(event) {
34 // Retrieve the Form and submit button elements
35 var form = jQuery("#form");
36 var submit = jQuery(event.currentTarget);
37
38 // The server URL can be retrieved from the Form 'action' event
39 var url = form.attr('action');
40
41 // Use jQuery serialize function to serialize the Form controls into key/value pairs
42 // Note: the jQuery serialize function will *not* add the button name/value
43 // that submitted the form. We will add the submit button name/value manually
44 var formData = form.serialize();
45
46 // Append the form ID attribute so that Click can identify the Ajax target Control
47 formData+='&'+form.attr('id')+'=1';
48
49 // Append the name/value pair of the Submit button that submitted the Form
50 formData+='&'+submit.attr('name')+'='+submit.attr('value');
51
52 jQuery.post(url, formData, function(data) {
53 // Update the target div with the server response and style the div by adding a CSS class
54 var div = jQuery('#target');
55 div.addClass('infoMsg');
56 div.html(data);
57 });
58}
164function post_result(response, statusText, xhr, $form)
165{
166 // Parse the JSON response
167 var result = jQuery.parseJSON(response);
168 $('#js_news_message').attr('class', 'alert ' + result.type).html(result.message);
169 if (result.success == true)
170 {
171 votetable.fnDraw();
172 }
173
174 // Reshow the button to close the window!
175 Modal.parent().find(".ui-dialog-buttonset").show();
176}
29function postData(url, data, onSuccess) {
30 onSuccess = onSuccess || function(){};
31 var xhttp = new XMLHttpRequest();
32 xhttp.onreadystatechange = function() {
33 if (xhttp.readyState == 4 && xhttp.status == 200) {
34 onSuccess(xhttp.responseText);
35 }
36 };
37 xhttp.open("POST", url, true);
38 xhttp.send(data);
39}
11postForm( params, newTab = false ) {
12 const form = jQuery( '<form method=\'POST\' style=\'display:none;\'></form>' ).appendTo(
13 document.body
14 );
15
16 if ( newTab ) {
17 form.attr( 'target', '_blank' );
18 }
19
20 for ( const i in params ) {
21 if ( params.hasOwnProperty( i ) ) {
22 $( '<input type="hidden" />' )
23 .attr( {
24 name: i,
25 value: params[i]
26 } )
27 .appendTo( form );
28 }
29 }
30
31 form.submit();
32 form.remove();
33}
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}

Related snippets