zoukankan      html  css  js  c++  java
  • 知问前端--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);
    }
    },
    });
    }
    }
    });

  • 相关阅读:
    javascript的语法作用域你真的懂了吗
    网页的三种布局(固定宽度式,流体式,弹性式)
    css3系列之animation
    跟我学习css3之transition
    函数调用你知道几种方法
    javascript的那些事儿你都懂了吗
    css3的那些高级选择器二
    [转]影响Cache的几个HTTP头信息
    CSS属性合写
    defer 与 async
  • 原文地址:https://www.cnblogs.com/qinsilandiao/p/5019391.html
Copyright © 2011-2022 走看看