知问前端--Ajax

本节课主要是创建一个问题表,将提问数据通过 ajax 方式提交出去。然后对内容显示
进行布局,实现内容部分隐藏和完整显示的功能。

一.Ajax 提问
创建一个数据表:question,分别建立:id、title、content、user、date。
然后创建一个 PHP 文件:add_content.php
//新增提问代码
<?php
sleep(3);
require 'config.php';
$query = "INSERT INTO question (title, content, user, date)
VALUES ('{$_POST['title']}', '{$_POST['content']}', '{$_POST['user']}', NOW())";
mysql_query($query) or die('新增失败!'.mysql_error());
echo mysql_affected_rows();
mysql_close();
?>
//jQuery 代码
$('#question').dialog({
autoOpen : false,
modal : true,
resizable : false,
width : 500,
height : 360,
buttons : {
'发布' : function () {
$(this).ajaxSubmit({
url : 'add_content.php',
data : {
user : $.cookie('user'),
content : $('.uEditorIframe').contents().find('#iframeBody').html(),
},
beforeSubmit : function (formData, jqForm, options) {

$('#loading').dialog('open');
$('#question').dialog('widget').find('button').eq(1).button('disable');
},
success : function (responseText, statusText) {
if (responseText) {
$('#question').dialog('widget').find('button').eq(1).button('enable');
$('#loading').css('background', 'url(img/success.gif) no-repeat
20px center').html('数据新增成功...');
setTimeout(function () {
$('#loading').dialog('close');
$('#question').dialog('close');
$('#question').resetForm();
$('.uEditorIframe').contents().find('#iframeBody').html('请
输入问题描述!');
$('#loading').css('background', 'url(img/loading.gif)
no-repeat 20px center').html('数据交互中...');
}, 1000);
}
},
});
}
}
});

转载于:https://www.cnblogs.com/qinsilandiao/p/5019391.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值