每次我运行此代码时,我都会得到" VALUE IS EMPTY"信息。意味着变量不会从Jquery传递到PHP变量$value
。我需要将它传递给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?
}
});
});
});
- &gt;无需插入表格代码..希望这能澄清我的问题
答案 0 :(得分:1)
你的html页面,我们将它命名为index.html(与php脚本不同!):
if(!IsPostBack) {
...
if(!IsPostBack) {
...
}
}
你的php脚本
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DropDownList1.DataBind(); // get the data into the list you can set it
DropDownList1.Items.FindByValue("SOMECREDITPROBLEMS").Selected = true;
}
}
最后:请阅读有关ajax如何工作的信息,请阅读manuals!