0
私は2つのテキストボックスをフォームに持っています。jqueryは、テキストボックスの値を取得し、コントローラの動作に渡す
テキストボックス内に値を入力してボタンをクリックすると、この値が関数に反映されます。
私のテキストボックスの価値を取って、javascriptとajaxを使用してボタンのクリックでコントロール機能でこれを渡したいと思います。
が、私のスクリプトが動作しないと...
<script>
$(document).ready(function() {
$("#subvessels").on('click', function() {
var shipment_title = $("#shipment_title").val(); //textbox value
var shipment_point = $("#shipment_point").val(); //textbox value
if (shipment_point) {
var dataString = 'shipment_title=' + shipment_title;
var dataString = 'shipment_point=' + shipment_point;
var values = $(this).serialize();
ajaxRequest = $.ajax({
url: '<?php echo Router::url(array("controller" => "DispatchedJobs", "action" => "approxBudget")); ?>',
type: 'POST',
data: dataString,
dataType: "html",
beforeSend: function() {
$('.spinicon').show();
},
success: function(response) {
$("#vessels_table").html(response);
},
complete: function() {
$('.spinicon').hide();
}
});
}
});
});
</script>
//controller function
public function approxBudget($shipment_point,$shipment_title)
{
echo $shipment_title;
echo $shipment_point; exit();
}
var dataString = 'shipment_title =' + shipment_title + '&shipment_point =' + shipment_point;これを使用する –
なぜ複雑な文字列ビルドとオーバーヘッドを使用し、オブジェクトによる値だけをjQueryに渡さないのですか? Mutchは読みやすくメンテナンス性に優れています。 – eisbehr