($width) AND $width .= 'px';
$style = " style=\"width: $width\"";
}
$value = $value ? $value : date('H:i');
$s = " ";
return $s;
}
// form_date('start', '2018-07-05') 为空则当前日期
function form_date($name, $value = 0, $width = FALSE)
{
$style = '';
if (FALSE !== $width) {
is_numeric($width) AND $width .= 'px';
$style = " style=\"width: $width\"";
}
$value = $value ? $value : date('Y-m-d');
$s = " ";
return $s;
}
/**用法
*
* echo form_radio_yes_no('radio1', 0);
* echo form_checkbox('aaa', array('无', '有'), 0);
*
* echo form_radio_yes_no('aaa', 0);
* echo form_radio('aaa', array('无', '有'), 0);
* echo form_radio('aaa', array('a'=>'aaa', 'b'=>'bbb', 'c'=>'ccc', ), 'b');
*
* echo form_select('aaa', array('a'=>'aaa', 'b'=>'bbb', 'c'=>'ccc', ), 'a');
*/
?>组保留的标签 余下为需要删除的标签
unset($oldtag[$key]);
}
}
}
if (!empty($oldtag)) {
$tagids = array();
foreach ($oldtag as $tagid => $tagname) {
$tagids[] = $tagid;
}
well_oldtag_delete($tagids, $tid);
}
$r = well_tag_process($tid, $fid, $create_tag, $tagarr);
return $r;
}
// 删除标签和绑定的主题
function well_oldtag_delete($tagids, $tid)
{
$pagesize = count($tagids);
$arrlist = well_tag_find_by_tagids($tagids, 1, $pagesize);
$delete_tagids = array(); // 删除
$tagids = array();
$n = 0;
foreach ($arrlist as $val) {
++$n;
if (1 == $val['count']) {
// 只有一个主题
$delete_tagids[] = $val['tagid'];
} else {
$tagids[] = $val['tagid'];
}
}
!empty($delete_tagids) and well_tag_delete($delete_tagids);
$arlist = well_tag_thread_find_by_tid($tid, 1, $n);
if ($arlist) {
$ids = array();
foreach ($arlist as $val) $ids[] = $val['id'];
well_tag_thread_delete($ids);
}
!empty($tagids) and well_tag_update($tagids, array('count-' => 1));
}
// 标签数据处理 $arr=新提交的数组 $tagarr=保留的旧标签
function well_tag_process($tid, $fid, $new_tags = array(), $tagarr = array())
{
if (empty($tid)) return '';
// 新标签处理入库
if ($new_tags) {
$threadarr = array();
$tagids = array();
$i = 0;
$size = 5;
$n = count($tagarr);
$n = $n > $size ? $size : $size - $n;
foreach ($new_tags as $name) {
++$i;
$name = trim($name);
$name = stripslashes($name);
$name = strip_tags($name);
$name = str_replace(array(' ', '#', "@", "$", "%", "^", '&', '·', '<', '>', ';', '`', '~', '!', '¥', '……', ';', '?', '?', '-', '—', '_', '=', '+', '.', '{', '}', '|', ':', ':', '、', '/', '。', '[', ']', '【', '】', '‘', ' ', ' ', ' ', ' ', ' '), '', $name);
$name = htmlspecialchars($name, ENT_QUOTES);
if ($name && $i <= $n) {
// 查询标签
$read = well_tag_read_name($name);
if ($read) {
// 存在 count+1
$tagids[] = $read['tagid'];
} else {
// 入库
$arr = array('name' => $name, 'count' => 1);
$tagid = well_tag_create($arr);
FALSE === $tagid and message(-1, lang('create_failed'));
$read = array('tagid' => $tagid, 'name' => $name);
}
$tag_thread = array('tagid' => $read['tagid'], 'tid' => $tid);
$threadarr[] = $tag_thread;
$tagarr[$read['tagid']] = $read['name'];
}
}
!empty($threadarr) and tag_thread_big_insert($threadarr);
!empty($tagids) and well_tag_update($tagids, array('count+' => 1));
}
$json = empty($tagarr) ? '' : xn_json_encode($tagarr);
return $json;
}
?>return $r;
}
/**
* @param int $page 页数
* @param int $pagesize 每页显示数量
* @return mixed
*/
function link_find($page = 1, $pagesize = 100)
{
$arr = link__find($cond = array(), array('rank' => -1), $page, $pagesize);
return $arr;
}
/**
* @param $id
* @return bool 返回FALSE失败 TRUE成功
*/
function link_delete($id)
{
if (empty($id)) return FALSE;
$r = link__delete(array('id' => $id));
link_delete_cache();
return $r;
}
//--------------------------kv + cache--------------------------
/**
* @return mixed 返回全部友情链接
*/
function link_get($page = 1, $pagesize = 100)
{
$g_link = website_get('friends_link');
if (empty($g_link)) {
$g_link = link_find($page, $pagesize);
$g_link AND website_set('friends_link', $g_link);
}
return $g_link;
}
// delete kv and cache
function link_delete_cache()
{
website_set('friends_link', '');
return TRUE;
}
?> $v = implode(",", $v);
$temp[] = $v;
}
// 去掉重复的字符串,也就是重复的一维数组
$temp = array_unique($temp);
// 再将拆开的数组重新组装
$output = array();
foreach ($temp as $k => $v) {
if ($stkeep) $k = $starr[$k];
if ($ndformat) {
$temparr = explode(",", $v);
foreach ($temparr as $ndkey => $ndval) $output[$k][$ndarr[$ndkey]] = $ndval;
} else $output[$k] = explode(",", $v);
}
return $output;
}
// 合并二维数组 如重复 值以第一个数组值为准
function array2_merge($array1, $array2, $key = '')
{
if (empty($array1) || empty($array2)) return NULL;
$arr = array();
foreach ($array1 as $k => $v) {
isset($v[$key]) ? $arr[$v[$key]] = array_merge($v, $array2[$k]) : $arr[] = array_merge($v, $array2[$k]);
}
return $arr;
}
/*
* 对二维数组排序 两个数组必须有一个相同的键值
* $array1 需要排序数组
* $array2 按照该数组key排序
* */
function array2_sort_key($array1, $array2, $key = '')
{
if (empty($array1) || empty($array2)) return NULL;
$arr = array();
foreach ($array2 as $k => $v) {
if (isset($v[$key]) && $v[$key] == $array1[$v[$key]][$key]) {
$arr[$v[$key]] = $array1[$v[$key]];
} else {
$arr[] = $v;
}
}
return $arr;
}
?>
Ajax.-软件玩家 - 软件改变生活!
Ajax.
Ajax
Asynchronous JavaScript and XML(异步的 JavaScript 和 XML):
AJAX 不是新的编程语言,而是一种使用现有标准的新方法。 AJAX最大的优点是在不重新加载整个页面的情况下,可以与服务器交换数据并更新部分网页内容 。 AJAX 不需要任何浏览器插件,但需要允许JavaScript在浏览器上执行 (这点不用考虑)。
AJAX是基于现有的Internet标准,并且联合使用XMLHttpRequest 对象 (异步的与服务器交换数据)、JavaScript/DOM (信息显示/交互)、 CSS (给数据定义样式)、XML (作为转换数据的格式)。
AJAX应用程序与浏览器和平台无关。
了解更多:AJAX菜鸟教程
Ajax原理
Ajax基本结构(Jqurey)
$.ajax({ url:"发送请求(提交或读取数据)的地址", dataType:"预期服务器返回数据的类型", type:"请求方式", async:"true/false",data:{发送到/读取后台(服务器)的数据,json字符串},success:function(data){请求成功时执行}, error:function(){请求失败时执行}
});
ajax参数均为选填,如果不设置,按默认值处理:
url 默认为当前页地址
dataType 可用类型: xml:返回XML文档,可用Jquery处理。 html:返回纯文本HTML信息。 script:返回纯文本JavaScript代码。 json:返回json数据。 jsonp:(JSON with Padding) 是 json 的一种"使用模式",可以让网页从别的域名获取资料,即跨域读取数据。 text:返回纯文本字符串。 (如果不指定,Jquery将自动根据http包mime信息返回responseXML或responseText,并作为回调函数参数传递)
type 可用类型主要为post和get两种(默认为GET): GET:从指定的资源请求数据(从服务器读取数据) POST:向指定的资源提交要被处理的数据(向服务器提交数据) GET 还是 POST? 与 POST 相比,GET 更简单也更快,并且在大部分情况下都能用。然而,在以下情况中,请使用 POST 请求:
无法使用缓存文件(更新服务器上的文件或数据库) 向服务器发送大量数据(POST 没有数据量限制) 发送包含未知字符的用户输入时,POST 比 GET 更稳定也更可靠
async 异步方式,默认为true,即异步方式。当设置为false时,为同步方式。 异步方式:ajax执行后,会继续执行ajax后面的脚本,直到服务器端返回数据后,触发ajax里的success方法,这时候执行的是两个线程。 同步方式:在没有返回值之前,同步请求将锁住浏览器,用户其它操作必须等待请求完成才可以执行。
data 请求的数据,{ }中可以填入多项数据。如果不填(一般为get请求),则读取对应地址的全部数据,此时可以在console中通过console.log(res)显示数据情况。
success 和 error 两个函数 一般需要设置,方便确定请求是否成功,以及请求成功后的提示或是对数据的处理和显示。
实例:
<script type="text/javascript" src=".js"></script><script type="text/javascript">function Save(event){var url = "../updata_setting/updata";$.ajax({type: "POST",url: url,data: JSON.stringify(vm.updata_setting),success: function(r){if(r.code === 0){alert('操作成功', function(index){vm.reload();});}else{alert(r.msg);}}});}</script>
END
本文标签:
Ajax
更多相关文章 jquery中的ajax封装逻辑,jQuery里面ajax请求的封装 为了避免ajax漫天飞,我们需要对jQuery的代码进行封装,封装代码: function api_request(name, params, cb, scope, asyn
Data insertion after clicking a button does not work (script, AJAX, PHP) 1 - the button "Choice" has Id "ButtonPubVideoHdp" in Elementor2 - the file wp-contentthemesgener
javascript - Difference between fetch, ajax, and xhr - Stack Overflow What is the difference between these 3 calling methods? I'm using fetch in my current project and
解决浏览器直接get能获取数据而ajax post却不能 分析 打开控制台发现会有这条错误信息: has been blocked by CORS policy: The ‘Access-Control-Allow-Origin’ header co… 而直接get是有数据的,说明服务器是正
Jquery, ajax, javascript - getting an element by id - Stack Overflow I have some ajax onclick stuff that updates this line when the value is selected from the menu:<li i
javascript - Google Storage API - Resumable Upload, AJAX, CORS Error - Stack Overflow Getting a strange error.When a user wants to upload a file, they send an AJAX request to my server. My
javascript - jquery, ajax, load post result to div - Stack Overflow I have a form that I need to post and show the result in a div. I'm not having any problems making
javascript - Nonces, AJAX, script variables & security in WordPress Alright, so let's say you develop a website where you enqueue a js script on a page X of your frontend, using:wp_e
javascript - jQuery, ajax, display page inside of other page (like iframe) - Stack Overflow I need to display a page inside of a page, like an iframe, but using jquery. The pages are not on the s
javascript - Datatables refresh with draw(), ajax, pagination - Stack Overflow I'm trying to refresh my table with data from the server every few seconds.It's loading the
Submit Return False, But Still Submit Form - PHP, Javascript, AJAX, CodeIgniter - Stack Overflow This is probably going to sound backwards. I need for a form to submit return false, but still submit t
发表评论