【发布时间】:2012-04-12 22:44:17
【问题描述】:
我正在使用 ajax 调用调用 php 函数,但它不起作用。当我单击行的任何列时,我有一个包含一些行的表,它的值可以编辑,但是当我编辑值并单击另一列或输入更改的值时,不会再次显示。实际上我正在做一个 ajax 调用,我在其中更改表中列的数据,但它没有调用该 php 函数。
我的脚本如下
<script type="text/javascript" >
$(document).ready(function()
{
$(".edit_tr").click(function()
{
var ID=$(this).attr('id');
$("#span_"+ID).hide();
$("#input_"+ID).show();
}).change(function()
{
var ID=$(this).attr('id');
var input=$("#input_"+ID).val();
var dataString = 'id='+ ID +'&data='+input;
$("#span_"+ID).html('<img src="load.gif" />'); // Loading image
if(input.length>0)
{
$.ajax({
type: "POST",
url: "worker_app::edit_ajax()",
data: dataString,
cache: false,
success: function(html)
{
$("#span_"+ID).html(span);
}
});
}
else
{
alert('Enter something.');
}
});
// Edit input box click action
$(".editbox").mouseup(function()
{
return false
});
// Outside click action
$(document).mouseup(function()
{
$(".editbox").hide();
$(".text").show();
});
});
HTML 表格如下所示
<tbody>
<tr id="{IDWORKERS}" class="edit_tr">
<td class="edit_td">
<span id="span_{IDWORKERS}" class="text">{FIRM}</span>
<input type="text" value="{FIRM}" class="editbox" id="input_{IDWORKERS}" />
</td>
</tr>
</tbody>
而 php 函数位于 apps 文件夹中的一个名为 wroker_app.php 的文件中
public function edit_ajax(){
///echo "<pre>";
///print_r($_POST);
//echo "</pre>";
// sql to update the database goes here
echo 'I am here';
}
有什么想法吗?
提前致谢
【问题讨论】:
-
我不知道什么都没发生 :( 我是 ajax 新手,如何检查 ajax 调用?
-
alert(html) inside 成功并告诉我们结果