一个功能页面上的多个AJAX功能 [英] Multiple AJAX functions on one functions page
问题描述
我想找到一种在每个Web部分的根目录中都有一个页面来容纳我正在调用的所有databae查询的方法.
I'd like to find a way of having a single page in the root of each of my web sections to hold all of the databae queries I'm calling.
我正在使用一个小脚本.....
I'm using a little script .....
<script type="text/javascript">
$(function() {
var availableTags = <?php include('fn-search-em.php'); ?>;
$("#quick-add").autocomplete({
source: availableTags,
autoFocus:true
});
});
</script>
....以执行在用户键入时出现的SQL搜索.与此类似....
.... to do SQL searches that appear as the user is typing. Similar to this ....
$sql = "SELECT * FROM stock_c_colours WHERE current_c_status = 'current' AND deleted = 'no'";
$result = mysqli_query($conn, $sql);
$results_list = array();
while($row = mysqli_fetch_array($result))
{
$colour_id = $row['id'];
$range_name = $row['range_name'];
$range_colour = $row['colour'];
$colour_code = $row['code'];
$p1 = $row['piece_size_1'];
$p2 = $row['piece_size_2'];
if($p1 > 1){
$p_mark = 'x';
}
else {
$p_mark = '';
}
$results_list[] = $range_name.' ('.$range_colour.' '.$colour_code.' '.$p1.$p_mark.$p2.') ID:'.$colour_id;
}
echo json_encode($results_list);
将JSON数组形式的列表回显到文本框,然后回荡一个列表.但是,由于各种原因(用户请求),我目前正在工作的网站上大约有20个搜索框,这是否意味着我必须拥有20个独立的php函数页面,每个页面上都有自己的查询,或者可以使用一页吗?
Echos a list in the form of a JSON array back to the text box and voila, a list. However, the site I'm working on at the moment has about 20 search boxes for various reasons scattered around (user request), does this mean I have to have 20 separate php function pages, each with their own query on, or can a single page be used?
我怀疑Java需要做一些修改才能在多个查询的页面上调用特定功能,但是我对Java不太满意,因此将不胜感激.
I suspect the java needs modifying a little to call a specific function on a page of multiple queries, but I'm not good with Java, so some help would be greatly appreciated.
我最初确实尝试在Java脚本中的PHP地址的末尾添加?action =,希望另一端的GET能够将PHP的末尾分成几部分,但是没有运气.
I did initially try adding ?action= to the end of the PHP address in the Java script, hoping a GET on the other end would be able to separate the PHP end into sections, but had no luck.
推荐答案
您需要更改<?php include('fn-search-em.php');?> ;;
转换为<?php $ action ='mode1';包括('fn-search-em.php');?> ;;
.
然后在您的 fn-search-em.php
文件中,使用 $ action
变量来确定您进行哪种MySQL查询.
Then in your fn-search-em.php
file, use the $action
variable to determine what kind of MySQL query you make.
例如:
if ($action == 'mode1')
$sql = "SELECT * FROM stock_c_colours WHERE current_c_status = 'current' AND deleted = 'no'";
else
$sql = "SELECT * FROM stock_c_colours WHERE current_c_status = 'mode1' AND deleted = 'no'";
这篇关于一个功能页面上的多个AJAX功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!