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:
- HTTP 405 Error: Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
- Error: required request body is missing, @ requestbody annotation usage
- When to enter success and error in AJAX
- JS prompt cannot read property ‘style’ of undefined
- Uncaught Error: _registerComponent(…): Target container is not a DOM element
- Four ways to get Django parameters in request
- Microsoft JScript runtime error: ‘sys’ is undefined
- Encapsulation of Axios and management of API interface in Vue
- Solve the problem that the delete request is not available under SpringBoot. There was an unexpected error (type=Method Not Allowed, status=405).
- How to Fix “Slow Access of Stackoverflow” Issue
- React Native: TypeError: Network request failed
- IntegrityError at ** NOT NULL constraint failed: learning_logs_topic.owner_id
- JS Ajax request is successful, the response displays “failed to load response data”
- CSRF verification failed. Request aborted.
- Encapsulation of Ajax JSON / fromdata request in native JS
- Post build event after VC generation
- ASP.NET AJAX client-side framework failed to load
- Certificate chaining error in sphere
- Router DIO network request: dioerror[ DioErrorType.RESPONSE ]: HTTP status error [400] or [500]
- Solve the problem of request method ‘get’ not supported