2015-01-11 31 views
0

试图获取Wordpress插件中的发送数据,但无法让数据正常工作。那么如何从PHP文件中的序列化部分获取数据?无法访问PHP文件中的AJAX的序列化数据

//代码

<form method="post" id="form-settings" action="ajaxpro.php" > 

    <?php wp_nonce_field('settings', 'settings_nonce', false);?> 

    <input name="field-one" type="text"/> 
    <input name="field-two" type="text"/> 
    <textarea name="field_three">Hello world</textarea> 

    // notice the double fields 

    <input name="field-x[]" type="text"/> 
    <input name="field-x[]" type="text"/> 
    <input name="field-x[]" type="text"/> 
    <input name="field-x[]" type="text"/> 
    <input name="field-x[]" type="text"/> 

    <button id="submitme" name="save-form">Save</button> 

</form> 



$('body').on('submit', '#form-settings', function(e){ 

    var seri =$(this).serializeArray() 
    $.post(ajaxurl, { 
     action: 'save_ajax_func', 
     posted: seri 
    }, function(response) { 
     console.log(response);  
    }); 


    return false; 

}); 


//notice that I do use double field names(field-x) 

echo $_POST[ 'posted' ][ 'field-one' ] // not working 
+0

是的,我忘了把上面的演示放在演示里面;-) – user759235

+0

让我们看看表单的HTML – Musa

回答

0

在HTML使用[]符号这将是posted[field-x]

<input name="posted[field-x]" type="text"/> 

阿贾克斯将不得不改变,以低于

var seri = $(this).serializeArray(); 
seri.push({name:'action',value:'save_ajax_func'}); 
$.post(ajaxurl, seri, function(response) { 
     console.log(response);  
});