每次運行此代碼時,都會收到「VALUE IS EMPTY」消息。意味着變量不會從Jquery傳遞給PHP變量$value
。我需要將它傳遞給PHP。幫我!無法從Jquery發送值到PHP
(#popup
是一個div它出現在單擊表TR時)
HTML + PHP代碼:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="popup">
<?php
if (isset($_POST['val']) && !empty($_POST['val']))
{
$value = $_POST['val'];
echo $value;
}
else{
echo "VALUE IS EMPTY";
//each time I get this msg.. means it won't take the variable value to PHP
}
?>
</div>
的JQuery/Javascript代碼:
$(document).ready(function(){
$('#tableview tbody tr').click(function(){
var a=[];
$(this).find('td').each(function(){
a.push($(this).text());
});
$('#popup').show();
$.ajax({
url:'addfile.php',
data:{'val': a[1] },
type:'post',
success:function(res){
//Is there an error due to this function? or what?
}
});
});
});
- >沒有必要插入代碼的表..希望這可以澄清我的問題
你使用模型彈出或簡單的div? –
所以'console.log(a)',你看到了什麼? –
@MuhammadUsman ..很簡單div –