我有一个javascript函数,它在更改下拉列表时执行:
<script type="text/javascript">
$(function()
{
// Executes when the status dropdown changes value
$('select[name="status_dropdown"]').change(function(event)
{
var $this = $(event.target);
var orderId = $this.closest('tr').children('td:eq(0)').text(); // index 0 refers to the "order_id column" in the table
var result = null;
var scriptUrl = "ajax_php/update_status.php?order_id=" + orderId + "&status_id=" + this.value;
$.ajax(
{
url: scriptUrl,
type: 'get',
dataType: 'html',
async: false,
success: function(data)
{
result = data;
alert(result);
}
});
});
})
</script>
我正在尝试获取警报调用以显示以下php代码的返回值(这是真的):
<?php
.
.
.
return true;
?>
警报不会弹出。任何人都知道为什么???
答案 0 :(得分:2)
我使用其他网址尝试了您的代码并且运行良好。 有三种情况:
如果向ajax参数添加错误处理程序,则可以查看错误的详细信息:
error : function(jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
答案 1 :(得分:1)
返回仅返回php脚本中的值 - 要将其输出到ajax,您需要将结果实际输出到页面,在这种情况下类似echo "true";
或print("true");
答案 2 :(得分:-1)
试试这个
$(document).ready(function(){
$('select[name="status_dropdown"]').change(function(event)
{
var $this = $(event.target);
var orderId = $this.closest('tr').children('td:eq(0)').text(); // index 0 refers to the "order_id column" in the table
var result = null;
var scriptUrl = "ajax_php/update_status.php?order_id=" + orderId + "&status_id=" + this.value;
$.ajax(
{
url: scriptUrl,
type: 'get',
dataType: 'html',
async: false,
success: function(data)
{
result = data;
alert(result);
}
});
});
});