将数组文本输入值发布到ajax

时间:2017-08-28 12:24:23

标签: php jquery ajax

我想使用AJAX检索输入值,即数组。

<td>
 <label for=""><?php _e( 'State' ); ?></label>
 <input type="text" name="state_to[<?php echo $country_id ?>][]" class=" state_selection" placeholder="State name">
</td>

$('.location-wrapper').on('change', '.state_selection', function() {

        var country = $('#country_selection').val();
var self = $(this),
    data = {
        //state_id : self.find(':selected').val(),
        state_id : $('input[name="state_to[country][]"]').val(),
        country_id: $('#country_selection').val(),
        action    : 'select_zip_by_state_country'       
    };

    }); 

我能够检索正确的值fpr国家,但不能检索州。请有人帮帮我吗?

1 个答案:

答案 0 :(得分:1)

您可以使用解决方案

$('.location-wrapper').on('change', '.state_selection', function() {
  var country = $('#country_selection').val();
  var self = $(this),
  data = {
    //state_id : self.find(':selected').val(),
    state_id : $('input[name="state_to[' + country + '][]"]').val(),
    country_id: $('#country_selection').val(),
    action    : 'select_zip_by_state_country'       
  };
}); 

希望这会对你有所帮助。