0
嗨,我正在將jFormer庫整合到Wordpress中,並通過Ajax調用進入WordPress。我已經註冊了我的Ajax左撇子在WordPress插件如下:jQuery表格發送額外的帖子變量AJAX
add_action('wp_ajax_nopriv_jFormerForWp', 'JFormerForWP::AjaxHandler');
add_action('wp_ajax_jFormerForWp', 'JFormerForWP::AjaxHandler');
本質上講,我需要做的是在POST請求發送一個變量稱爲動作=> jFormerForWp。
問題是我的jQuery技能是有限的,我問過開發人員,他們可能會回到我身邊,但他們認爲我會打開這一般的jQuery社區,希望他們能夠提供幫助。
所以要確認,我需要修改jQuery代碼來發送action = jFormerForWp。
代碼在這裏http://www.jformer.com/download/jFormer-dev.zip與下面摘錄,我認爲請求是由形式。非常感謝,克里斯
submitForm: function(event) {
var self = this;
// Use a temporary form targeted to the iframe to submit the results
var formClone = this.form.clone(false);
formClone.attr('id', formClone.attr('id')+'-clone');
formClone.attr('style', 'display: none;');
formClone.empty();
formClone.appendTo($(this.form).parent());
// Wrap all of the form responses into an object based on the component jFormComponentType
var formData = $('<input type="hidden" name="jFormer" />').attr('value', encodeURI(jFormerUtility.jsonEncode(this.getData()))); // Set all non-file values in one form object
var formIdentifier = $('<input type="hidden" name="jFormerId" value="'+this.id+'" />');
formClone.append(formData);
formClone.append(formIdentifier);
this.form.find('input:file').each(function(index, fileInput) {
if($(fileInput).val() != '') {
// grab the IDs needed to pass
var sectionId = $(fileInput).closest('.jFormSection').attr('id');
var pageId = $(fileInput).closest('.jFormPage').attr('id');
//var fileInput = $(fileInput).clone()
// do find out the section instance index
if($(fileInput).attr('id').match(/-section[0-9]+/)){
var sectionInstance = null;
var section = $(fileInput).closest('.jFormSection');
// grab the base id of the section to find all sister sections
var sectionBaseId = section.attr('id').replace(/-section[0-9]+/, '') ;
sectionId = sectionId.replace(/-section[0-9]+/, '');
// Find out which instance it is
section.closest('.jFormPage').find('div[id*='+sectionBaseId+']').each(function(index, fileSection){
if(section.attr('id') == $(fileSection).attr('id')){
sectionInstance = index + 1;
return false;
}
return true;
});
fileInput.attr('name', fileInput.attr('name').replace(/-section[0-9]+/, '-section'+sectionInstance));
}
// do find out the component instance index
if($(fileInput).attr('id').match(/-instance[0-9]+/)){
// grab the base id of the component to find all sister components
var baseId = $(fileInput).attr('id').replace(/-instance[0-9]+/, '')
var instance = null;
// Find out which instance it is
$(fileInput).closest('.jFormSection').find('input[id*='+baseId+']').each(function(index, fileComponent){
if($(fileComponent).attr('id') == $(fileInput).attr('id')){
instance = index + 1;
return false;
}
return true;
});
fileInput.attr('name', $(fileInput).attr('name').replace(/-instance[0-9]+/, '-instance'+instance));
}
$(fileInput).attr('name', $(fileInput).attr('name')+':'+pageId+':'+sectionId);
$(fileInput).appendTo(formClone);
}
});
// Submit the form
formClone.submit();
formClone.remove(); // Ninja vanish!
// Find the submit button and the submit response
if(!this.options.debugMode){
this.controlNextButton.text(this.options.submitProcessingButtonText).attr('disabled', 'disabled');
}
else {
this.form.find('iframe:hidden').show();
}
},
感謝Vibhu,我一直在與其他Ajax函數調用瞎搞,感謝你已經把我的幫助回到正軌。 – g18c