$("#btn_edit").click(function(){
var token = localStorage.getItem('id_token');
var obj = {};
obj.subject = $("input[name=subject]").val();
obj.description = $("textarea[name=description]").val();
$.ajax({
type: "PUT",
url: "http://myurl",
contentType: "application/json",
dataType: "json",
data: JSON.stringify(obj),
success: function(jsonresponse) {
$(document.body).append(JSON.parse(jsonresponse));
},
beforeSend: function(xhr, settings) {
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
}
});
});
但是当手动添加值时,它可以很好地工作,甚至输入值也会打印在警报中
alert("Text: " + $("input[name=subject]").val() + " " + $("textarea[name=description]").val());
var obj = {};
obj.subject = "Hello";
obj.description = "Help please";