PHP文本不会在AJAX调用上进入textarea

时间:2014-09-17 08:30:32

标签: javascript php jquery html ajax

我遇到了一个我无法解决的问题。

我有一个表单,表单内部是<textarea>,其中已填充了文本。我的问题是,当我去查看表单时,文本显示在textarea之外,而不是内部存在问题!

我有以下内容:

HTML

<div class="passenger_Container">
    <div class="names">
        <strong>Joe Bloggs</strong>
    </div>

    <div class="package">
        <!-- passenger detail goes here. You will find the code in  includes/passenger_Detail.php -->
    </div>
</div> <!-- .passenger_Container -->

的jQuery

j$('.names strong').click(function(e) {
        //find passenger ID - note input[name='customer_ID'] isn't shown in this example
        var customer_ID = j$(this).closest('.passenger_Container').find("input[name='customer_ID']").val();
        //Use jQuery to find placement of returned data
        var insert_Data = j$(this).closest('.passenger_Container').find('.package');


        j$.ajax({        
           type: "POST",
           url: "/include/passenger_Detail.php",
           data: { customer_ID_Data : customer_ID },
           success: function(data) {
                //console.log("Returned data: "+data);  
                //get returned data and add into appropriate place
                insert_Data.html(data);

                //re-initialise WYSIWYG editor. Notes is the ID to re-initialize 
                tinyMCE.execCommand('mceAddControl', true, 'notes');
           }
        }); 
    });

PHP - passenger_Detail.php

<?php
$customer_ID = $_REQUEST['customer_ID_Data'];
$query = mysqli_query($conn,"SELECT * FROM Customers WHERE customer_ID = ".$customer_ID." ORDER BY l_Name asc")
    or die("Error: ".mysqli_error($conn));
$row = mysqli_fetch_array($query);
$orderQuery = mysqli_query($conn,"SELECT * FROM Orders WHERE customer_ID=".$row['customer_ID']."")
    or die("Error: ".mysqli_error($conn));
$rowOrder = mysqli_fetch_array($orderQuery);
?>
<textarea type="text" name="notes" class="form-control notes" id="notes" />
<?php 
    echo $rowOrder['Notes']; 
?>
</textarea>

TL; DR - 文本回显($rowOrder['Notes'];)在PHP文件中显示在textarea之外,而不在内部。

我不知道造成这种情况的原因。任何帮助都会很棒!

1 个答案:

答案 0 :(得分:4)

textarea开头标记中删除尾部斜杠:

而不是:

<textarea type="text" name="notes" class="form-control notes" id="notes" />

它应该是:

<textarea type="text" name="notes" class="form-control notes" id="notes">