javascript - 如何为 Ajax 数据分配默认值或预加载数据
问题描述
我正在使用复选框创建一个过滤器并且能够做到。但是,我的问题是如何在不向#response提交表单的情况下分配默认或预加载循环。执行下面的脚本将返回一个循环。我正在尝试学习 ajax,但在 PHP 中,逻辑类似于
$response = 'myloop';
echo $response; // display the default loop
if ($search == 'true') {
$response = 'mynewloop'; // change the default loop
}
else {
$response = 'myloop'; // return to default loop
}
这是我的ajax jquery
jQuery(function($){
$('#filter').submit(function(){
var filter = $('#filter');
$.ajax({
url:filter.attr('action'),
data:filter.serialize(), // form data
type:filter.attr('method'), // POST
beforeSend:function(xhr){
filter.find('button').text('Processing...'); // changing the button label
},
success:function(data){
filter.find('button').text('Apply filter'); // changing the button label back
$('#response').html(data); // insert data
}
});
return false;
});
});
解决方案
推荐阅读
- java - 在 FileNet ContentEngine 中搜索文件夹并检索其类
- c# - 以编程方式在 vsdx 文件中创建/操作 visio 绘图
- r - R,层次聚类标签?
- wordpress - 有人知道这种滑块吗?
- intellij-idea - 如何获取 Kotlin IntelliJ 暂存文件的输出?
- html - 如何使用 css 定位和设置 Google recaptcha 样式?
- javascript - 使用 Javascript 更改线性渐变不起作用
- google-maps - Flutter:Flutter 中是否提供谷歌地图街景?
- c# - 找不到添加对项目的引用的按钮
- codeigniter - 调用 CodeIgniter 控制器方法返回 404