• 知问前端--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);
    }
    },
    });
    }
    }
    });

  • 相关阅读:
    Leetcode: Rotate Image
    Leetcode: Longest Palindromic Substring && Summary: Palindrome
    Leetcode: Reverse Nodes in k-Group
    Leetcode: Substring with Concatenation of All Words
    Leetcode: Merge k Sorted List
    Summary: Java中函数参数的传递
    Leetcode: Generate Parentheses
    超级wifi
    路由器中继(repeater)模式 和 AP+WDS模式区别?
    route 的标志位
  • 原文地址:https://www.cnblogs.com/qinsilandiao/p/5019391.html
Copyright © 2020-2023  润新知