Ajax表单提交 - 单击更改html元素文本时

时间:2014-09-06 14:32:53

标签: javascript php jquery html ajax

所以我正在尝试创建一个消息系统。当我点击消息打开我的模板时,在同一页面中打开消息内容。我想尝试做:“看”按钮 - > ajax->替换为jquery .text(“Blah Blah”)。问题是,当我尝试tod

HTML代码:

<form method="POST">
                <button type="button" class="btn btn-small btn-success" name="msg_preview_id" value="'.$inbox_row['id'].'">New</button>
            </form>

Jquery Ajax表单:

$(document).ready(function(){
$('button[name=msg_preview_id]').click(function(event) {

                var formData = {'msg_preview_id' : $('button[name=msg_preview_id]').val()};                


        $.ajax({
            type        : 'POST', // define the type of HTTP verb we want to use (POST for our form)
            url         : '../../class/messages/inbox_preview.php', // the url where we want to POST
            data        : formData, // our data object
            dataType    : 'json' // what type of data do we expect back from the server                        
        })

            .done(function(data) {                            

                console.log(data);                                                        

                                //Email Stuff
                                $('h1[id=emailheading]').text(""+data.info.subject+"");
                                $('a[id=emailfrom]').text(""+data.info.from+"");
                                $('span[id=emaildate]').text(""+data.info.rcvdat+"");
                                $('p[id=emailtext]').text(""+data.info.text+"");

                                //Ceninhas
                                $('#inbox-wrapper').addClass('animated fadeOut');
                $('#inbox-wrapper').hide();                 
                $('#preview-email-wrapper').addClass('animated fadeIn ');           
                $('#preview-email-wrapper').show();         
                //$('.page-title').show();  
                //Load email details
                $('#inbox-wrapper').removeClass('animated fadeOut');            
                $('#inbox-wrapper').removeClass('animated fadeIn');

            });                   

                        event.preventDefault();         
});
});

PHP:

<?php

include ('../../inc/config.inc.php');

$data = array();
$info = array();

$Msg_Preview_ID = $_POST['msg_preview_id'];

$MsgSQL = mysqli_query($Connection, "SELECT * FROM messages_inbox WHERE id='$Msg_Preview_ID'");
$Msg = mysqli_fetch_assoc($MsgSQL);

$bzQuery = mysqli_query($Connection, "SELECT * FROM members_profile WHERE id='".$Msg['from']."'");
$bzFetch = mysqli_fetch_assoc($bzQuery);

$info['from'] = $bzFetch['fname']." ".$bzFetch['lname'];
$info['subject'] = $Msg['subject'];
$info['text'] = $Msg['text'];
$info['rcvdat'] = $Msg['rcvdat'];

$data['info']  = $info;

echo json_encode($data);

1 个答案:

答案 0 :(得分:0)

我在其他pge中使用$ _GET []它更容易!