尝试将变量传递给HTML模式,运行查询并根据id显示信息...我可以将参数传递给HTML但我需要在最后的SQL WHERE语句结束时使用它查询...
我的脚本在这里。我想我需要一些ajax来实现这一目标。我创造了一个小提琴
http://jsfiddle.net/rbla/y7s5tf3p/
<script>
$(document).on("click", ".open-AddBookDialog", function () {
var myBookId = $(this).data('id');
//$(".modal-body #bookId").val( myBookId );
document.getElementById("bookId").innerHTML = myBookId;
});
</script>
变量被插入到HTML中,但我需要将data-id转换为php变量而不是HTML,以便我可以运行查询......
这是我的PHP文件
<?php
$id = ( this is where the data-id needs to be );
$sql = oci_parse($conn, select * from movies m where id=:id");
oci_bind_by_name($sql, ':id', $id);
oci_execute($sql, OCI_DEFAULT);
$objResult = oci_fetch_array($sql);
?>
答案 0 :(得分:0)
是的,你需要AJAX来做你想做的事。
请注意,$(this).data('id')
将获得与以下内容类似的标记属性的值:
<input type="text" data-id="mother" id="17" />
它会获取值mother
,而不是17
。
以下代码示例可能类似于您需要构建的代码:
<强>的javascript / jQuery的:强>
$(document).on("click", ".openSlickModal-1", function () {
var myMovieId = $(this).data('id');
$.ajax({
type: 'post',
url: 'my_ajax_processor.php',
data: 'MovieID=' +myMovieId,
success: function(d){
alert(d); ////Just for testing: disable after receiving the correct response
$("#movie").html(d);
}
});
});
<强> my_ajax_processor.php:强>
<?php
$id = $_POST['MovieID'];
die('Received: ' .$id); //Just a test: disable this after receiving the correct response
//do your query using the $id
$out = 'Whatever you create (HTML or plain text) after your query
echo $out;
?>
其他参考文献:
Prevent Page Load on Jquery Form Submit with None Display Button