|
|
|
ใช้ jquery ajax ต้องการที่จะส่ง value จาก checkbox ต้องกำหนด data ยังไงครับ |
|
|
|
|
|
|
|
Code (JavaScript)
$('#result').html('<img src="images/ajax-progress.gif" alt="loader" />').show();
var url = $('#add_hotel').attr('action');
var hotel_information = CKEDITOR.instances['hotel_information'].getData();
var hotel_breakfast = CKEDITOR.instances['hotel_breakfast'].getData();
var hotel_internet = CKEDITOR.instances['hotel_internet'].getData();
var hotel_bts = CKEDITOR.instances['hotel_bts'].getData();
var hotel_shuttle = CKEDITOR.instances['hotel_shuttle'].getData();
var hotel_name_kr = $('#hotel_name_kr').val();
var hotel_name_en = $('#hotel_name_en').val();
var hotel_rating = $('#hotel_rating').val();
var hotel_build = $('#hotel_build').val();
var hotel_room = $('#hotel_room').val();
var hotel_address = $('#hotel_address').val();
var hotel_province = $('#hotel_province').val();
var hotel_telephone = $('#hotel_telephone').val();
var hotel_url = $('#hotel_url').val();
var room_chk = $('input:checkbox[name=room_chk]:checked').serializeArray();
var hotel_chk = $('input:checkbox[name=hotel_chk]:checked').serializeArray();
$('#hotel_chk :checked').each(function() {
hotel_chk.push($(this).val());
});
var mode = $('#mode').val();
$.ajax({
type: 'POST',
url: url,
dataType: 'html',
data:
{
hotel_name_kr: hotel_name_kr,
hotel_name_en: hotel_name_en,
hotel_rating: hotel_rating,
hotel_build: hotel_build,
hotel_room: hotel_room,
hotel_address: hotel_address,
hotel_province: hotel_province,
hotel_telephone: hotel_telephone,
hotel_url: hotel_url,
room_chk: room_chk,
hotel_chk: hotel_chk,
hotel_information: hotel_information,
hotel_breakfast: hotel_breakfast,
hotel_internet: hotel_internet,
hotel_bts: hotel_bts,
hotel_shuttle: hotel_shuttle,
mode: mode
},
success: function(data){
$('#result').html(data).show();
/*if(data == 1){
$('#result').html('<div class="success">Create Success</div>').show();
} else {
$('#result').html('<div class="error">Create Error</div>').show();
}*/
}
});
Code (PHP)
<?php
while ($roomResult = mysql_fetch_array($roomQuery)){ ?>
div id="characteristic"><input type="checkbox" id="room_chk" name="room_chk[]" value="<ฦ=$roomResult['characteristic_room_id']; ?>"><?=$roomResult['characteristic_room_name']; ?></div>
<?php
}
?>
ลองใช้ serializeArray(); แล้ว ก็ไม่ได้ครับ
Tag : PHP, JavaScript, Ajax
|
|
|
|
|
|
Date :
2012-10-26 10:29:28 |
By :
Necrotorture |
View :
1911 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองดูตัวอย่างจากลิงค์นี้นะครับ ---> http://api.jquery.com/checked-selector/
|
|
|
|
|
Date :
2012-10-26 17:47:07 |
By :
คนธรรมดา |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองดูจากตัวอย่างนี้นะครับ
http://ricochen.wordpress.com/2011/08/02/passing-array-of-checkbox-values-to-php-through-jquery-example/
|
|
|
|
|
Date :
2012-10-26 22:36:04 |
By :
phongs |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|