今日、私はset_valueのIDを持つすべてのテキストボックスをループし、その名前と値をキー値配列に設定してから、ajaxリクエストに渡します。すべての入力名と値をajaxに渡すGET
問題は、IDの最初の出現を見ているだけです。だれかがその理由を知っていますか?
は、これはJS
function saveSettings() {
var myFieldsValue = {};
$("#setting_value").each(function() {
myFieldsValue[this.name] = $(this).val();
alert(this.name + ' = ' + $(this).val());
});
$.ajax({
url: '/' + 'api/ajax/higher/save_game_settings',
type: "GET",
data: myFieldsValue,
statusCode: {
400: function (response) {
showErrorNotification("Something went wrong", response.responseText, 3000);
},
500: function (response) {
showErrorNotification("Something went wrong", response.responseText, 3000);
}
},
success: function(data) {
showSuccessNotification("Action Completed", "Settings have been updated.", 1000);
}
});
}
あるこのHTMLです
<div class="ibox-content" style="">
<h2>Main Game Settings</h2>
<p>Mainline In-Game configuration</p>
<hr>
@foreach($gameSettings as $key => $setting)
<div class="row">
<div class="col-md-6">
<b>{{ $setting->setting_key }}</b><br>
{{ $setting->setting_description }}
</div>
<div class="col-md-6">
<input type="text" id="setting_value" name="{{ $setting->setting_key }}" value="{{ $setting->setting_value }}" class="form-control">
</div>
</div>
<hr>
@endforeach
<div class="btn btn-info" onclick="saveSettings();">Save Changes</div>
</div>
</div>
これはPHPやC++とどう関係していますか? – CoryKramer
PHPフレームワークで書かれています@CoryKramer –
jQueryの[。seriaize()](https://api.jquery.com/serialize/)を見てみてください。 –