【发布时间】:2016-08-28 17:15:09
【问题描述】:
我需要 url 中的 id 来创建 mysql_query。问题是我需要通过 Ajax 调用进行此操作,而 $_GET['id'] 显然不起作用。 有没有一种简单的方法可以让自己摆脱这种状态? 谢谢你:)
这是我的 ajax 调用:
echo "<div id='loading_utilizadores' class='loading'><img src='".$CONF['HOME']."/images/structure/ajax-loader.gif'/></div>";
echo "<div id='utilizadores'></div>";
echo "<script type='text/javascript'>";
echo "CarregaAjax(\"#utilizadores\",\"#loading_utilizadores\",\"".$CONF['HOME']."/superadmin/box_utilizadores_ajax.php\", \"GET\")";
echo "</script>";
ajax函数:
function CarregaAjax(id,loading,page,method){
if(method=="GET"){
$(document).ready(function(){
//$(loading).ajaxStart(function(){
$(loading).show();
$(id).hide();
//});
$(id).load(page);
$(loading).ajaxStop(function(){
$(loading).hide();
$(id).show();
});
});
}
else{
$(document).ready(function(){
//$(method).submit(function() {
$(loading).show();
$(id).load(page,$(method).serializeArray());
$(loading).hide();
return false;
//});
});
}
和 html ajax 调用的和平。在此页面中,我尝试创建 $_GET['id'],但没有成功。
if (isset($_GET['id']))
{
$officeID = intval($_GET['id']);
}
else
{
$officeID = 0;
}
if(!isset($crm_users))$crm_users = new crm_utilizadores;
//$officeID = 12;
$resultGetUsers = $crm_users->getUsersByOfficeId($officeID);
$html = "<table class='table1' width='100%' cellpadding='5' cellspacing='1' border='0'>";
if(!empty($resultGetUsers)){
$html .= "<tr>";
$html .= "<td class='table_title1'>Utilizador</td>";
$html .= "<td class='table_title1'>Telefone</td>";
$html .= "<td class='table_title1'>Telemóvel</td>";
$html .= "<td class='table_title1'>E-mail</td>";
$html .= "<td class='table_title1'>Situação</td>";
$html .= "</tr>";
}else{
$html .= "<tr><td class='empty1'>não foram encontrados utilizadores registados neste cliente</td></tr>";
}
//finalizar a tabela
$html .= "</table>";
我想我错了,对吧? :p
【问题讨论】:
-
除非我没有正确阅读此代码,否则这是您在 AJAX 中调用的 URL:
/superadmin/box_utilizadores_ajax.php该 URL 中没有id值或任何其他值。 -
我使用 ajax 函数从 php 加载文件,在本例中为 /superadmin/box_utilizadores_ajax.php。这个文件应该在已经写在包括这个文件的其他文件中的 HTML 之上写一些 HTML。我使用这种 $_GET 技术,它通常可以工作。使用此 ajax 调用,无法正常工作:/
-
它“工作”很好。 URL没有您要查找的查询字符串参数。这看起来像这样:
/superadmin/box_utilizadores_ajax.php?id=123$_GET集合在 URL 中查找查询字符串参数。它会找到它如果它在那里。但是,在您的代码中,它不存在。 -
问题是当那个php被执行时,url看起来像这样:myurl/index.php?view=deleteOffice&id=12
-
现在您谈论的是完全不同的页面。
index.php和box_utilizadores_ajax.php是不同的页面。哪个具有尝试从 URL 检索值的代码? (问题中显示的代码。)您可能会在某个时候将该值发送到index.php,但根据问题中发布的代码,您不会将其发送到box_utilizadores_ajax.php。