[英]Error with AJAX and PHP referencing
I've been looking at this for a while and I think the major issue is the file i am referencing but I am not sure. 我已经看了一段时间了,我认为主要的问题是我正在引用的文件,但我不确定。 I am working with a large amount of php files scattered all over the project folder but in the immediate folder I am working with files NavBar.php which is called using a require() statement in layout.php here's the code I am having trouble with (btw all of this code is in NavBar.php):
我正在处理散布在项目文件夹中的大量php文件,但在直接文件夹中,我正在处理NavBar.php文件,这是使用layout.php中的require()语句调用的,这是我遇到的代码(顺便说一下,所有这些代码都在NavBar.php中):
<?php
$db=mysql_connect('localhost','root','');
if(!$db) {
die('Could not connect: '.mysql_error());
}
$connection_string=mysql_select_db('shipreq_stagetest',$db);
$selectSQL='SELECT * FROM color_patterns';
$queryset=mysql_query($selectSQL);
$num=mysql_num_rows($queryset);
if(0==$num) {
echo "No record";
exit;
} else {
while($row=mysql_fetch_assoc($queryset)) {?>
<li class= "list_item" onclick="<?php $indx = $_POST['pat_id'];?>">
<?php echo($row['name']);?></li><?php
}
}
?>
I know the sql calls are outdate and I should change it to PDOs I will make the switch as soon as I can figure out why the AJAX isn't working. 我知道sql调用已过期,我应该将其更改为PDO,一旦我弄清楚为什么AJAX无法正常工作,就将进行切换。 this php code makes a db call and retrieves some data which displayed in the li (new li generated for each row in the table)(dropdown) and when a user clicks it I want to use this JS function to save the index of the clicked li to a php variable (hence the AJAX, I am really new to AJAX so I am having trouble figuring it out):
此php代码进行数据库调用,并检索显示在li(为表中的每一行生成的新li)中显示的一些数据(下拉列表),当用户单击它时,我想使用此JS函数保存被单击的索引li到一个php变量(因此AJAX,我对AJAX真的很陌生,所以我很难弄清楚它):
<script>
$(document).on('click', '.list_item', function() {
var indx = $(this).index();
$.ajax({ // add ajax code here
type: 'POST',
url: 'layout.phtml',
data: {pat_id: indx}, // send parameter like this
success: function(response) {
console.log(response);
}
});
});
</script>
I think the major issue might be the file I am referencing since NavBar.php is referenced by layout.phtml which is probably required by some other document in the hierarchy. 我认为主要问题可能是我正在引用的文件,因为NavBar.php被layout.phtml引用了,而层次结构中的某些其他文档可能会要求它。 this is the error I get in the console when I click on the li:
这是我单击li时在控制台中遇到的错误:
jquery.min.js:4 XHR finished loading: POST " http://localhost/shiprequest/layout.phtml ".send @ jquery.min.js:4ajax @ jquery.min.js:4(anonymous function) @ shiprequest?lang=en:235dispatch @ jquery.min.js:3r.handle @ jquery.min.js:3 shiprequest?lang=en:240
jquery.min.js:4 XHR完成加载:POST“ http://localhost/shiprequest/layout.phtml ” .send @ jquery.min.js:4ajax @ jquery.min.js:4(匿名函数)@ shiprequest? lang = en:235dispatch @ jquery.min.js:3r.handle @ jquery.min.js:3 shiprequest?lang = en:240
( ! ) Fatal error: Uncaught exception 'Zend_Acl_Exception' with message 'Resource 'shiprequest_layout.phtml' not found' in C:\\sgm\\library\\Zend\\Acl.php on line 364 ( ! ) Zend_Acl_Exception: Resource 'shiprequest_layout.phtml' not found in C:\\sgm\\library\\Zend\\Acl.php on line 364 Call Stack #TimeMemoryFunctionLocation 10.0006145888{main}( )..\\index.php: 0 20.0018168016require_once( 'C:\\sgm\\application\\bootstrap.php' )..\\index.php
: 5 30.11182860576Zend_Controller_Front->dispatch( )..\\bootstrap.php
: 124
(!)致命错误:第364行的C:\\ sgm \\ library \\ Zend \\ Acl.php中出现未捕获的异常'Zend_Acl_Exception',消息为'资源'shiprequest_layout.phtml'(!)Zend_Acl_Exception:资源'shiprequest_layout.phtml'在第364行的C:\\ sgm \\ library \\ Zend \\ Acl.php中找不到调用堆栈#TimeMemoryFunctionLocation 10.0006145888 {main}().. \\ index.php : 0 20.0018168016require_once('C:\\ sgm \\ application \\ bootstrap.php ').. \\ index.php
: 5 30.11182860576Zend_Controller_Front-> dispatch().. \\ bootstrap.php
: 124
From the message error provided by you: 根据您提供的消息错误:
Uncaught exception 'Zend_Acl_Exception' with message 'Resource 'shiprequest_layout.phtml' not found
找不到消息为“资源'shiprequest_layout.phtml”的未捕获异常'Zend_Acl_Exception'
Validate if shiprequest_layout.phtml exist. 验证是否存在shiprequest_layout.phtml。 You probably wanted to write shiprequest_layout.html and not .phtml
您可能想编写shiprequest_layout.html而不是.phtml
<script>
$(document).on('click', '.list_item', function() {
var indx = $(this).index();
$.ajax({ // add ajax code here
type: 'POST',
url: 'layout.html', <------ here
data: {pat_id: indx}, // send parameter like this
success: function(response) {
console.log(response);
}
});
});
</script>
EDIT from Comments: 编辑评论:
If you file is really layout.phtml, then your error is in file Acl.php (C:\\sgm\\library\\Zend\\Acl.php) at line 364
. 如果您的文件确实是layout.phtml,那么您的错误是
file Acl.php (C:\\sgm\\library\\Zend\\Acl.php) at line 364
。 Line 364 is trying to find shiprequest_layout.phtml
if this file do not exist, you will get this error. 如果该文件不存在,则第364行尝试查找
shiprequest_layout.phtml
,您将收到此错误。
You probably mean layout.phtml
instead of shiprequest_layout.phtml
您可能是指
layout.phtml
而不是shiprequest_layout.phtml
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.