0
$(document).ready(function() {
$(".submit").click(function(event) {
event.preventDefault();
var user_name = $("input#name").val();
var password = $("input#pwd").val();
jQuery.ajax({
type: "POST",
url: "<?php echo base_url(); ?>" + "index.php/ajax_post_controller/user_data_submit",
dataType: 'json',
data: {
name: user_name,
pwd: password
},
success: function(res) {
if (res) {
// Show Entered Value
jQuery("div#result").show();
jQuery("div#value").html(res.name);
jQuery("div#value_pwd").html(res.pwd);
}
}
});
});
});
// the function of controller that the url: contains
public function user_data_submit() {
$data = array(
'username' => $this - > input - > post('name'),
'pwd' => $this - > input - > post('pwd')
);
echo json_encode($data);
}
このコードは、入力フィールドから値を取り出し、idに基づいてHTMLにフィードするために使用されます。しかし私の問題は、私はすでにデータを持っているデータベースから価値をもたらす選択クエリからそれをフィードする必要があります。ajaxを使用してデータベースから値をフィードする方法