1. Method 1: obtain form data through Jquery$("# corresponding form id). SerializeArray ()
, and directly assign values to $. Ajax
data.
.serializearray () method see jQuery ajax-serializearray () method
this method puts back an array of JSON objects.
$("#postSubmit").click(function () {
let data = $("#postContent").serializeArray();
$.ajax({
url: '/decuhub/home-post-ajax',
method: 'POST',
data: data,
async: true,
success: function (result) {
console.log("post successfully!")
}
})
})
2. The method 2: by $(" # corresponding form form id) serializer () code> to obtain the form data: p>
$("#postSubmit").click(function () {
let data = $("#postContent").serializer();
$.ajax({
url: '/decuhub/home-post-ajax',
method: 'POST',
data: data,
async: true,
success: function (result) {
console.log("post successfully!")
}
})
})
. Method 3:
is not recommended
$("#postSubmit").click(function () {
let postContentForm = $("#postContent").serializeArray();
let data = {};
$.each(postContentForm, function(){
data[this.name] = this.value;
})
$.ajax({
url: '/decuhub/home-post-ajax',
method: 'POST',
data: data,
async: true,
success: function (result) {
console.log("post successfully!")
}
})
})
$.each()
reference jQuery. Each () p b>
Django's request-post
gets
<QueryDict: {'csrfmiddlewaretoken': ['vO34OFZtTj2Bp2ARMlXVJxZQb37CyuWR7ywaDC4QaJhHtcxB4xB9fnb2IOnbQ2AR'], 'content': ['asdfsd']}>
div>
Read More:
- Three ways to get form data in struct2
- In the HTML page request Ajax times 400 error, solve Yii submit post form 400 error, and Ajax post request 400 problem (example code)
- No data: data: get host by name failed in TCP_ Connect() error resolution
- Struts 2 encapsulates form data into list and map sets
- Use XMLHttpRequest of JavaScript to send data to the background
- JS Ajax request is successful, the response displays “failed to load response data”
- About content type ‘multipart / form data…’ not support
- Four ways to get Django parameters in request
- Inconsistency between adapter data and UI data after dragging recyclerview (data disorder)
- error: Some data has already been output, can’t send PDF file
- @Solution to get / set error in eclipse after using data annotation
- Error in idea @ data entity class get / set
- IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly
- [MySQL] [serialize] [error record] after modifying data, no data will be returned (in fact, MySQL does not support it)
- How to Fix Sklearn ValueError: This solver needs samples of at least 2 classes in the data, but the data
- [idea] error occurred when using @ data annotation in Lombok: no related get / set method was found
- circuit_breaking_exception,“reason“:“[parent] Data too large, data for [<http_request>]
- An error is reported when passing data pages using Ajax: Vue is not defined
- HTML method IE8 reports an error, IE8 jQuery Ajax obtains static resources reports an error, typeerror denies access
- Ajax error reporting cross domain, AJAX cross domain access error 501 solution