我需要发送一个带有ajax的表单,代码接下来:
$("#myForm").submit(function (e) {
e.preventDefault();
$("#id_ask").val(id),
$("#id_text").val( $('#editor').markdownEditor('content') )
console.log($("#id_text").val())
ForumService.create_answer($("#myForm"), URL);
})
我明白了:
My content
POST http://127.0.0.1:8080/API/forum/answer/ 400 (BAD REQUEST)
这意味着,id_text
值尚未发送。
所见$("#id_text").val( $('#editor').markdownEditor('content') )
太慢了,它在ForumService.create_answer(URL);
怎么能解决这个问题?
我尝试过:.change()
和$.when()
由于
的Ajax:
ForumService.create_answer = function (form, url)
{
formData = new FormData($(form).get(0));
$.ajax({
type: 'POST',
url: url,
data: formData,
processData: false,
contentType: false,
beforeSend :
function( xhr ) {
xhr.setRequestHeader( "Authorization", JSON.parse($.session.get("Token")).token_type +" "+ JSON.parse($.session.get("Token")).access_token );
}
...
})
有效载荷:
------WebKitFormBoundaryVPuu073tJX2oNFzh
Content-Disposition: form-data; name="ask"
1
------WebKitFormBoundaryVPuu073tJX2oNFzh
Content-Disposition: form-data; name="text"
------WebKitFormBoundaryVPuu073tJX2oNFzh
Content-Disposition: form-data; name="action"
------WebKitFormBoundaryVPuu073tJX2oNFzh--