This is my ajax call.
这是我的ajax电话。
$(document).on('click','#Quote_create_value',function(){
$.ajax({
type : 'GET',
url : '../../../protected/config/ajax.php',
success : function(response){
$("#Quote_template_value").html(response);
}
});
});
I have many methods in ajax.php. Each and every method throws some response.
我在ajax.php中有很多方法。每种方法都会引发一些反应。
<?php
function respose()
{
$query = "select * from quote where template IS NOT NULL";
$result = mysql_query($query, $con);
while ($row = mysql_fetch_assoc($result)) {
echo '<option value="'.$row['template'].'">' . $row['template'] . '</option>';
}
$query1 = "select * from template";
$data = mysql_query($query1,$con);
while ($row = mysql_fetch_assoc($data)) {
echo json_encode($row);
}
}
function result()
{
}
?>
But i want to get response from one method [ie. from response()].
但我想从一种方法得到回应[即。来自response()]。
How can this be done?
如何才能做到这一点?
1 个解决方案
#1
0
You could include a selector in the ajax request data. Like this for example:
您可以在ajax请求数据中包含一个选择器。像这样举例如:
$(document).on('click','#Quote_create_value',function(){
$.ajax({
type : 'GET',
url : '../../../protected/config/ajax.php',
data: "function=result",
success : function(response){
$("#Quote_template_value").html(response);
}
});
});
Then in your PHP code, a simple if-statement will check which one to output.
然后在PHP代码中,一个简单的if语句将检查输出哪一个。
if(isset($_GET['function'])) {
if($_GET['result'] == 'result') {
// do result stuff
} elseif($_GET['function'] == 'response') {
// do response stuff
}
}
#1
0
You could include a selector in the ajax request data. Like this for example:
您可以在ajax请求数据中包含一个选择器。像这样举例如:
$(document).on('click','#Quote_create_value',function(){
$.ajax({
type : 'GET',
url : '../../../protected/config/ajax.php',
data: "function=result",
success : function(response){
$("#Quote_template_value").html(response);
}
});
});
Then in your PHP code, a simple if-statement will check which one to output.
然后在PHP代码中,一个简单的if语句将检查输出哪一个。
if(isset($_GET['function'])) {
if($_GET['result'] == 'result') {
// do result stuff
} elseif($_GET['function'] == 'response') {
// do response stuff
}
}