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);
    }
    },
    });
    }
    }
    });

  • 相关阅读:
    学习Java的Day02
    学习Java的Day01
    多线程的了解
    几个MQ的区别
    HTML5——存储(cookie、localStorage、sessionStorage)的区别
    dubbo mock配置
    Springboot分布式,excel导出,运用POI导出,前端用的jsp
    oracle 添加字段和添加注释
    可以重复的Map:IdentityHashMap
    数组转list问题
  • 原文地址:https://www.cnblogs.com/qinsilandiao/p/5019391.html
Copyright © 2011-2022 走看看