简体   繁体   中英

Ajax Form Submit - When click change html element text

So I'm trying to create a message system. When I click on the Message to open my template opens in the same page the message content. I'm trying to make like: "See" Button->ajax->replace with jquery .text("Blah Blah"). the problem is that when I try tod

HTML Code:

<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 Form:

$(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);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM