0
私はサーバーにajaxリクエストを作成しようとしています。要求は正常に送信されますが、パラメータは要求本文に適切ではありません。ブラウザのネットワークツールを使って体に示すjavascript - ajaxはnullデータを要求します
パラメータ:彼らはすべきではないが、
{"name":"","message":"","time":1464807897670}
名<input>
とメッセージ<textarea>
フィールドは、空です。
ここに私のHTMLの入力フィールドです:
<div id="writePanel">
<p>Your Name</p>
<input id="writeName" type="text">
<p>Message</p>
<textarea id="writeArea"></textarea>
<div id="sendButton">Send</div>
</div>
はここでJSのコードです:
$(document).ready(function() {
var data = {
name: document.getElementById("writeName").value,
message: document.getElementById("writeArea").value,
time: new Date().getTime()
};
$("#sendButton").click(function() {
$.ajax({
type: "POST",
url: "message.receive",
contentType: "application/json",
data: JSON.stringify(data),
success: function (response) {
// ...
}
})
})
})
私は何をしないのですか?
は、これが唯一のJSを実行していますか?最初に値をクリアすることができますか?同じIDを持つ他の要素がページにありますか? – Trey
完全にそれを逃した、@ zack.loreそれを釘付け – Trey