在我的代碼片段下面我的Ajax會發送一些數據到response.php。如果我想通過Ajax發送更多數據,我該如何繼續?我想添加例如user_id,如我的HTML代碼底部所示。如何通過AJAX/JS發送更多數據
$(document).ready(function() {
$("#FormSubmit").click(function (e) {
e.preventDefault();
if($("#contentText").val()==='')
{
alert("Du følger allerede denne bloggen");
return false;
}
var myData = 'content_txt='+ $("#contentText").val();
jQuery.ajax({
type: "POST",
url: "assets/plugin/ajax-follow/response.php",
dataType:"text",
data:myData,
success:function(response){
$("#responds").append(response);
$("#contentText").val('');
},
error:function (xhr, ajaxOptions, thrownError){
alert(thrownError);
}
});
});
});
HTML
<div class="form_style">
<input type="hidden" name="content_txt" id="contentText" value="'.$user_info[u_id].'">
<input type="hidden" name="user_id" id="userid" value="'.$whotofollow[u_id].'">
<button id="FormSubmit">Følg</button>
</div>
我不認爲這工作。無法處理腳本。 – user2217702