我有一個提供數據庫值的php代碼。我需要JavaScript變量中的這些值。使用Ajax將PHP值傳遞給javascript
JavaScript代碼
<script src="http://code.jquery.com/jquery-1.8.0.js"></script>
<script type="text/javascript">
function text() {
var textVal=$("#busqueda_de_producto").val();
$.ajax(
{
type:"POST",
url:"index.php", //here goes your php script file where you want to pass value
data: textVal,
success:function(response)
{
// JAVSCRIPT VARIABLE = varable from PHP file.
}
});
return false;
}
</script>
PHP文件代碼:
<?php
$q11 = "select * from sp_documentocompra_detalle where dcd_codigo".$_GET['codigo'];
$res11 = mysql_query($q11);
$row11 = mysql_fetch_array($res11);
?>
http://whathaveyoutried.com/ –
在你的PHP代碼,只是做'回聲json_encode($ row11);' –
如果你只是想將變量從一個php頁面傳遞給另一個,只需使用SESSION。你只是從一個腳本變量,並傳回給index.php在你的HTML/JavaScript頁面中它們有什麼用處? – Champ