Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Ajax调用是在页面上的其他位置插入数据_Javascript_Php_Jquery_Html_Ajax - Fatal编程技术网

Javascript Ajax调用是在页面上的其他位置插入数据

Javascript Ajax调用是在页面上的其他位置插入数据,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,我正在使用ajax调用在页面的开头插入数据。这更像是一个墙贴脚本。每当用户发布内容时,最新发布的内容都会显示在“发布”页面的顶部 我正在使用JS、PHP和HTML页面 以下是我的js代码: $(function() { $("#tweet_submit").click(function() { var tweet = $("#tweet").val(); var x = $('.preview').attr('id'); if(x) va

我正在使用ajax调用在页面的开头插入数据。这更像是一个墙贴脚本。每当用户发布内容时,最新发布的内容都会显示在“发布”页面的顶部

我正在使用JS、PHP和HTML页面

以下是我的js代码:

    $(function() {
    $("#tweet_submit").click(function() 
    {
    var tweet = $("#tweet").val();
    var x = $('.preview').attr('id');
    if(x)
    var z= x;
    else
    var z=0;
    var dataString = 'tweet='+ tweet+ '&z=' +z;

    if(tweet=='')
    {
    alert('Please type your tweet here');
    }
    else
    {
    alert('into post');
    $.ajax({
    type: "POST",
    url: "WallPost/post_tweet1.php",
    data: dataString,
    cache: false,
    success: function(html){
    $("#tweet").val('');
    $("#preview").hide();
    $("#content").prepend(html);
    }
    });
    }return false;
    }); 
    });
这是我的PHP页面: post_tweet.php

    <?php
    include("includes/db.php");
    include("session.php");
    include_once 'includes/time_stamp.php';

    //echo "request sent to post";

    if($_POST)
    {

    $tweet=$_POST['tweet'];
    $upload_id=$_POST['z'];
    $time=time();

    $query = "INSERT INTO tweets(tweet,time,upload_id,uid_fk) VALUES ('$tweet','$time','$upload_id','$uid')";
    if (!mysqli_query($con,$query))
                                {
                                die('Error: ' . mysqli_error($con));
                                }
                                else
                                {
                                $msg ="<br> 1 record added";
                                }

    echo "<br>".$msg;
    $sql=mysqli_query($con,"select T.tid, T.tweet, T.time, T.upload_id, U.username, U.fullname, U.email FROM tweets T, users U WHERE T.uid_fk=U.uid and T.uid_fk='$uid' order by T.tid DESC LIMIT 1");
    //$show_result=mysqli_query($sql);
    while($row=mysqli_fetch_row($sql))
    {
    echo "data start here";
    $tid= "$row[0]";
    $tweet= "$row[1]";
    $time = "$row[2]";
    $img_id= "$row[3]";
    $username="$row[4]";
    $fullname = "$row[5]";
    $email = "$row[6]";
    $lowercase = strtolower($email);
    $imagecode = md5( $lowercase );

    $image_sql=mysqli_query($con,"select image_name from uploads where upload_id='$img_id'");
    while($data=mysqli_fetch_row($image_sql))
    {
    $image_name="$data[0]";
    $chars = 7; 

            $text = $image_name." "; 
            $text = substr($text,0,$chars);  
            $imgtext = "pic.twitter/".$text."...";

    }
    //echo "<div class='center'>";
    echo "<div class='tweet_box' id='$tid'>";
    echo "<div class='tweet_user'><img class='user_img' src='http://www.gravatar.com/avatar/$imagecode?s=50'></div>";
    echo "<div class='tweet_body'>";
    ?>
    <div class='tweet_time'><?php time_stamp($time);?></div>
    <?php
    echo "<div><b><a href='http://twitter.com/$username'>$fullname</a></b> <span class='uname'>@$username</span></div>";
    echo "<div class='tweet_text'>$tweet &nbsp;";
    if($img_id!=0)
    {
    echo "<a href=''/>$imgtext</a></div>";
    }
    else
    {
    echo "</div>";
    }
    echo "<div class='tweet_options'><div class='first_option'><a href='#'>Expand</a> </div><div class='sub_options'>&nbsp;&nbsp;<a href='#'>Reply</a> &nbsp;&nbsp;<a href='#'>Retweet</a> &nbsp;&nbsp;<a href='#'>Favourite</a></div></div>";

    if($img_id!=0)
    {

    ?>
    <div class="tweet_image" id="tweetimage<?php echo $tid; ?>">
    <center><img src="uploads/<?php echo $image_name; ?>" class="image_show"/></center></div>

    <?php
    }

    echo "</div></div>";
    ?>

    <div class="tweet_reply_box" id="replybox<?php echo $tid;?>">
    <div><textarea rel="<?php echo $tid;?>" id="replytext<?php echo $tid;?>" class="reply" name="reply" 

    maxlength="140">@<?php echo $username;?> </textarea></div>

    <div class="reply_button_bar" id="replybutton<?php echo $tid;?>">
    <div><input type="submit"  value=" Reply " class="reply_btn" id="<?php echo $tid;?>"/></div>
    </div>

    </div>

    <div id="reply_load<?php echo $tid;?>" class="reply_load">

    </div>


    <?php
    }

    }
    else { }
    ?>

您的输入帮助了我,我能够解决它。内容在两个位置被调用,ajax在第一个位置插入数据,而我没有将数据放在我需要的位置


谢谢。

内容似乎被插入到了
#content
元素pffffff的顶部。说真的,这相当于250行代码,javascript和HTML甚至没有缩进。帮助我们帮助您:请缩小代码范围并缩进。。。
    <!doctype html>
    <html>
    <head>
        <title>Design Modo - Code-pal | eCommerce Website Template - Dead Stocker</title>
        <link rel="shortcut icon" href="http://www.code-pal.com/wp-content/themes/codpeal-new/favicon.ico">
        <link rel="stylesheet" type="text/css" href="css/check_style.css" />
        <link rel="stylesheet" href="css/wallpost/wtfdiary.css">
        <link rel="stylesheet" href="css/wallpost/tipsy_title.css">
        <script type="text/javascript" src="WallPost/js/jquery.min.js"></script>
        <script type="text/javascript" src="WallPost/js/jquery.tipsy.js"></script>
        <script src="WallPost/js/twitter.js"></script>
        <script type="text/javascript" src="WallPost/js/jquery.form.js"></script>
    </head>
    <body>
        <div class="page-wrap">
        <div class="clear"></div>
        <?php include("header.php"); ?>
        <div class="clear"></div>
        <div class="body-contents">
            <?php include("left-body1.php"); ?>
            <div class="center">
                <br>
                    <div class="txthead"><strong>Share thoughts here</strong></div>
                <?php
                    include("WallPost/index.php");
                ?>
            </div>
        </div>
        <?php include("right-body.php"); ?>
        <div class="clear"></div>
        </div>
        <!-- eo .body-content -->
        <?php include("footer.php"); ?>
        </div><!-- eo .page-wrap-->
    <?php
    include("includes/db.php");
    include("session.php");
    include("includes/time_stamp.php");
    ?>

    <html>
    <head>

    <link rel="stylesheet" href="css/wtfdiary.css">
    <link rel="stylesheet" href="css/tipsy_title.css">

    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery.tipsy.js"></script>
    <script type="text/javascript" src="js/twitter.js"></script>
    <script type="text/javascript" src="js/jquery.form.js"></script>


    </head>

    <body>

    <div id="container">

    <div id="sidebar_container">
    <div id="sidebar">
    <div id='logo'><img src='images/1.png'></div>

    <div id="box">

    <div><textarea id="tweet" name="tweet" placeholder="Compose new Tweet..."></textarea></div>

    <div id='preview'></div>
    <div id="button_bar">
    <div id="icons">
    <div class="filebutton" title="Image Upload">
    <form id="imageform" method="post" enctype="multipart/form-data" action='ajax_image.php'>
    <span><input type="file" name="photoimg" id="photoimg"/></span>
    </form>
    </div>
    </div>
    <div><input type="submit"  value=" Tweet " class="btn" id="tweet_submit"/></div>

    </div>

    </div>
    </div>
    </div>
    <!-- <div id="main">  -->
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <div id='heading'>Tweets</div>
    <div id='content'>

    <?php include("loads_tweets1.php");?>

    <!-- </div>  -->
    </div>

    </div>

    </body>
    </html>