1
これは私のコードです:jQueryのAJAXのparams問題
$('body').on('click', '.update_contact_profile', function(){
var url = $("#ajaxUrl").val();
var ids = $(this).closest("div").nextAll(".contact-extra-info").find(".contact-ids").attr("id");
ids = ids.split("-")
var contactId = ids[0];
var customerId = ids[1];
var postDataUpdate = [];
$(this).closest("div").nextAll(".update_elements").find(".value :input").each(function(i, itemVal){
if ($(this).val()) {
postDataUpdate[''+$(this).attr('id')+''] = $(this).val();
}
});
var request = $.ajax({
url: url,
method: "POST",
data: {
id : contactId,
contact : postDataUpdate,
form_key : FORM_KEY,
customerId : customerId
}
});
request.success(function(text) { // replace the ajax_wrapper with the new one
$(".ajax_wrapper").replaceWith(text);
$("#contact_form").find('select').selectize();
});
request.fail(function(jqXHR, textStatus) {
alert("Request failed: " + textStatus);
});
});
私の問題は、このVAR postDataUpdate
は、それがアヤックスに渡されていなかったということです。火かき棒の上にcontact
は表示されません。私は私のアヤックスの要求の前にconsole.log(postDataUpdate)
をすれば私は私の配列を得た。
これについてのご意見はありますか?
[..]
var postDataUpdate = {};
$(this).closest("div").nextAll(".update_elements").find(".value :input").each(function(i, itemVal){
if ($(this).val()) {
postDataUpdate[''+$(this).attr('id')+''] = $(this).val();
}
});
[..]
チェックこのスニペット:
VAR postDataUpdate = [])。それは余分な括弧ですか? – Paul
'[]]' –
'に ')'がありますが、 '[]'が間違ったコピー貼り付けでした。それは問題ではない、私は私のポストを更新しました。コンソールにはエラーメッセージが表示されませんでした。 – Chester