是否可以显示带有ajax事件的php内容?

Sorry it is quite hard for me to ask the correct question, as I do not really know what I am doing... I have a form, where I include a php that is per default creating 3 different lines:

<form method="GET" name="NeuerLieferschein" action="Teileposten_INSERT.php">
<?PHP
    include ("NeuerLieferschein_Teilespalten.php");
?>

--> NeuerLieferschein_Teilespalten.php contains this loop that creates in the beginning 3 different lines with different fields called kunde1, kunde2, kunde3:

<?PHP
    if(isset($_POST['von']))
        {
        $von=trim($_POST['von']);
        $bis=$von;
        }
    else 
        {
        $von=1;
        $bis=3;
        }
for($i=$von; $i < ($bis+1); $i++)
    {
        require_once("DBFunctions.php");
        DBConnect();
        $sql="SELECT distinct Nachname, ';' FROM Kunde order by Nachname asc";
        $db->SetFetchMode(ADODB_FETCH_NUM);
        $Nachnamen=$db->Execute($sql);  
        echo '<select name="kunde'.$i.'" id="kunde'.$i.'" class="kunde'.$i.'" onclick="selectkunde('.$i.')" >';
        echo'<option selected="selected"> </option>';
        while (!$Nachnamen->EOF)
            {
            $Nachnamenzeile=($Nachnamen->fields);
            echo'<option value='.$Nachnamenzeile[0].'>'.$Nachnamenzeile[0].'</option>';
            $Nachnamen->MoveNext();
            }

        echo '</select> <br/>';
        DBClose();

This works fine. Now I want to have a new line created with an option id kunde4 if a button is clicked. And then a fith line with option kunde5 if somthing is clicked.

I added the following to the html page:

<div id="VariableZeilen" name="VariableZeilen" class="VariableZeilen">
    <p id="VariableZeilen" name="VariableZeilen" class="VariableZeilen">
    <!-- ADD NEW LINES HERE -->
    </p>
    </div>
    <tr>
    <td colspan=3>Zeilen erweitern auf<input id="clicked" size="4" onfocus="this.blur();" onclick="mehrTeile();" value="4">

And this as Javascript:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
var clickCount = 4;
function documentClick()
{
    document.getElementById('clicked').value = ++clickCount;
    return clickCount
}
document.onclick = documentClick;
function mehrTeile()
{
var von=document.getElementById('clicked').value;

var dataString = 'von='+ von;
alert ( ( dataString ) );
$.ajax
({
type: "POST",
url: "NeuerLieferschein_Teilespalten.php",
data: dataString,
cache: false,
complete: function (html) {
        //I get this alert, so I come so far:
        alert("ajax completed ");
        //This should show the output in the html section but nothing happens
    $(".VariableZeilen").html(html); 

      }
});
return false;  
}
</script>

Now I can see that with the alert the dataString is counting up every time I click. But what I am not able to, is to Show the php content of the NeuerLieferschein_Teilespalten.php in my <p id=VariableZeilen>

I am very new to Javascript so I guess it might be a very stupid question, but my searches in forums just didn't lead me to the right answers. I am very happy if someone can help me to code this for dummies. Thanks /Eve

Assuming your NeuerLieferschein_Teilespalten.php is working correct I would suggest some changes. You have an input field, however no matter the value there will always only be one field added due to your PHP script.

This is why I would change

Zeilen erweitern auf<input id="clicked" size="4" onfocus="this.blur();" onclick="mehrTeile();" value="4">

To something like the following

<input type="button" value="Eine Zeile hinzuf&uuml;gen" onclick="mehrTeile();" />

Now that you don't have an input field but only a button, you can just use the JavaScript variable for keeping track of the number of the field.

function mehrTeile()
{
    var dataString = 'von=' + clickCount; // we will increase clickCount later

Now to the main part of your script, the ajax. Instead of complete you need to use success, also if you use .html() you will always replace the content you loaded before. Meaning if you change it once and want to change it again, at the moment it won't keep the changes. Since you only add one row at a time that makes no sense, so .append() would be more wise.

All this would lead to the following

<form method="GET" name="NeuerLieferschein" action="Teileposten_INSERT.php">
<?PHP
    include ("NeuerLieferschein_Teilespalten.php");
?>
<p id="VariableZeilen"></p>
<input type="button" value="Eine Zeile hinzuf&uuml;gen" onclick="mehrTeile();" />

And this JavaScript

var clickCount = 4;
function mehrTeile()
{
    var dataString = "von="+clickCount;
    $.ajax({
        type: "POST",
        url: "NeuerLieferschein_Teilespalten.php",
        data: dataString,
        success: function(msg)
        {
            $("div#VariableZeilen").append(msg);
            clickCount++;
        }
    });
}

I would also suggest to edit the NeuerLieferschein_Teilespalten.php a bit. name="kunde'.$i.'" means that in the end you will have an unknown amount of fields and can't check it smooth. If you use name="kunde[]", you will get an array of all elements.

name="kunde'.$i.'"
-> $_POST['kunde1'] = ?
   $_POST['kunde2'] = ?
   $_POST['kunde3'] = ?
   $_POST['kunde4'] = ?

name="kunde[]"
-> $_POST['kunde'] = array(
   ?,
   ?,
   ?,
   ?,
)

Where ? simply leaves any value open

After analysing this issue for a long time, I have now discovered, that it works with Mozilla Firefox 20.0.1 but not with Internet Explorer 8.0.6 which is the latest version for the old windows XP machine I am using. Is there anything I can do to make this code also working with IE8? Is it about my table structure in PHP and HTML or is it about the response itself?

This is where my div is in the table:

<tr>
<td colspan=5>
<div id="VariableZeilen" class="VariableZeilen">
<!-- More Lines should appear here --> 
</div>
</td>
</tr>

And the php is adding more table structure like this:

for($i=$von; $i < ($bis+1); $i++)
{
echo '<tr>';
echo '<th rowspan="2" align=left>Bezeichnung: <input type="text" ';
echo 'name="Teileposition'.$i.'" id="Teileposition'.$i.'" size="50"></th>';
echo '<th rowspan="2"> Nettopreis: <input type="text" onblur="Calculatenettobrutto('.$i.');"';
echo 'name="Netto'.$i.'" id="Netto'.$i.'" size="3"></th>';
echo '<th rowspan="2">Brutto: <input type="text" ';
echo 'name="Brutto'.$i.'" size="3" id="Brutto'.$i.'"/></th>';
echo '<td>';
//Jetzt den Nachnamen auswählen
require_once("DBFunctions.php");
DBConnect();
$sql="SELECT distinct Nachname, ';' FROM Kunde order by Nachname asc";
$db->SetFetchMode(ADODB_FETCH_NUM);
$Nachnamen=$db->Execute($sql);  
echo '<select name="kunde'.$i.'" id="kunde'.$i.'" class="kunde'.$i.'" onclick="selectkunde('.$i.')" >';
echo'<option selected="selected"> </option>';
while (!$Nachnamen->EOF)
    {
    $Nachnamenzeile=($Nachnamen->fields);
    echo'<option value='.$Nachnamenzeile[0].'>'.$Nachnamenzeile[0].'</option>';
    $Nachnamen->MoveNext();
    }

echo '</select> <br/>';
DBClose();


    echo '</td>';
    echo '<th rowspan="2">';
    echo '<select name="Teilezurodnung" id="Teilezurodnung" size="1">';
    echo '<option value="Kunde" selected >Kunde</option>';
    echo '<option value="Lager" >Lager</option>';
    echo '<option value="Zurück" >Zurück</option>';
    echo '<option value="Falsch" >Falsch</option>';

    echo '</th>';
    echo '<tr><td>';
    //Je nach Nachname sollten hier die Autos erscheinen
    echo '<select name="auto'.$i.'" class="auto'.$i.'"><option selected="selected">--Wähle das Auto--</option></select>';
    echo '</td></tr>';
    echo '</tr>';