我是AJAX的新手,所以很抱歉,如果解决方案显而易见。
我必须在不刷新页面的情况下将日期发送到MySQL表,并且当前这样做有问题。

该代码给出
我出现以下错误:


“注意:未定义的索引:在第6行的inserisci.php中发布”


形成

 <form id="form" class="form-horizontal shadow-z-1" action="includes/inserisci.php" method="post">
        <fieldset>
            <legend style="text-align: center; position: relative; top: 8px;">Inserisci un Post</legend>
            <hr>
            <div class="form-group">
                <label for="inputTitle" class="col-lg-2 control-label">Titolo</label>
                <div class="col-lg-10">
                    <input type="text" class="form-control" id="inputText" name="titolo" placeholder="Scrivi qui il Titolo">
                </div>
            </div>
            <div class="form-group">
                <label for="textArea" class="col-lg-2 control-label" name="testo">Messaggio</label>
                <div class="col-lg-10">
                    <textarea id="messaggio"></textarea>
                </div>
                </div>

               <div class="form-group is-empty is-fileinput">
                    <label for="inputFile" class="col-md-2 control-label">File</label>

                    <div class="col-md-10">
                      <input type="text" readonly="" class="form-control" placeholder="Browse..." pmbx_context="19E61A0C-3526-4E51-8535-935982C4C335">
                      <input type="file" id="inputFile" multiple="" pmbx_context="1D2BCAEA-08CC-476A-8F4A-EF6BD51B9102">
                    </div>
                  <span class="material-input"></span></div>

            <div class="col-md-10 col-md-offset-2">
                      <button type="button" class="btn btn-default" onclick="document.getElementById('modalposta').style.display = 'none';">Cancel</button>
                      <button type="submit" class="btn btn-primary" onClick='send(); return false;' >Submit</button>
                    </div>
        </fieldset>
    </form>


INSERISCI.JS

  function send(){
var content = $.ajax({
        type: "POST",
        url: "index.php",
        data: {titolo:titolo & post:testo}
  })
  .done(function() {
    alert( "success" );
  })
  .fail(function() {
    alert( "error" );
  })
  .always(function() {
    alert( "complete" );
  });
}


INSERISCI.PHP

<?php

include('../core.php');

$titolo=$_REQUEST ['titolo'];
$post=$_REQUEST ['post'];

$sql = mysql_query("");

mysql_close();

?>


其他问题。
我需要重新加载此内容而不刷新页面。

索引文件

<?php $sql = mysql_query("")  or die ("Nessun errore");
    if (mysql_num_rows($sql) > 0)
    {


        while ($row = mysql_fetch_assoc($sql))
        {
            echo '

            <article class="flipper white-panel">
        <a class="flipcard flip" style="
        position: absolute;
        right: 0px;
        top: -10px;
        z-index:1;
    "><i class="material-icons" style="font-size: 40px;">bookmark</i></a>
        <div class="articolo">
        <img src="http://i.imgur.com/sDLIAZD.png" alt="">

            <h4><a href="#">'.$row ['titolo'].'</a></h4>
            <p>'.Markdown($row ['contenuto']).'</p>
             <div class="pull-right">
                            <span class="label label-default">alice</span>
                            <span class="label label-primary">story</span>
                            <span class="label label-success">blog</span>
                            <span class="label label-info">personal</span>
                            <span class="label label-warning">Warning</span>
                            <span class="label label-danger">Danger</span>
                          </div>
                          <hr>
                          </div>
        <div class="commenti">
            <ul class="comment-list">
                        <li>
                            <div class="comment-img">

                            </div>
                            <div class="comment-text">

                            </div>
                        </li>
                    </ul>
                    <input type="text" class="form-control inputcomment" placeholder="Lascia un Commento.."/>
                  </div>
      </article>
         ';
        }


    }


谢谢大家。

最佳答案

笔记:


请不要使用mysql_*功能。他们已弃用。
您的代码容易受到SQL注入攻击的攻击。请确保您解决它们。



那是语法错误。那不是有效的JavaScript对象。将您的data对象更改为:

data: {titolo:titolo, post:testo}


另外,在使用$.ajax之前,您还需要关闭.done

  var content = $.ajax({
        type: "POST",
        url: "index.php",
        data: {titolo:titolo & post:testo}           // Should be closed here.
  })
  .done(function() {
    alert( "success" );
  })                                                 // Should not be closed. Remove ;
  .fail(function() {
    alert( "error" );
  })                                                 // Should not be closed. Remove ;
  .always(function() {
    alert( "complete" );
  });
  // });                                                Remove this!


如果没有任何效果,请更改以下行:

$titolo = $_POST['titolo'];
$post = $_POST['post'];


等一下,您是否获得了这两个的值?

var titolo = $('input[name="titilo"]').val();
var testo = $('input[name="testo"]').val();

09-30 19:38