使用jQuery / JavaScript修改HTML表

I have a HTML page which has one div and table. Then I have a PHP script which sould print the HTML for a table. Anyway, the table will not be modified. Does my print command include some kind of special charasters or is there something else which could be the reason?

I have a file index.html with the following jQuery code:

$(document).ready(function(){
  setInterval(function() {
    var kaavio = 106;

    jQuery.post("search.php", {
      kaavio: kaavio
    }).done(function(data) {
      $('#check').html(data);
    });
  }, 6000);
});

Here is the HTML of the file index.html:

<div id="check"></div>
<table id="paikka59"></table>

I also have a PHP file search.php and here is the code of it:

print "<script>document.getElementById('paikka59').innerHTML = '<tr><td class=\"pisteet\" style=\"border-top:2px solid #16B2B4;padding:0\"><a href=\"#\" class=\"painike painike-pisteet hae-muokattavaksi\" data-kilpailu=\"106\" data-kaavio=\"106\" data-kaaviokierros=\"11\" data-kaaviopaikka=\"59\" data-ab=\"A\" data-ottelu=\"181510\" data-muokattava=\"pisteet\"></a></td><td class=\"nimi\" style=\"border-top:2px solid #16B2B4;padding:0\"><a href=\"#\" class=\"painike painike-hae-muokattavaksi hae-muokattavaksi\" data-kilpailu=\"106\" data-kaavio=\"106\" data-kaaviokierros=\"11\" data-kaaviopaikka=\"59\" data-ab=\"A\" data-ottelu=\"181510\" data-muokattava=\"nimi\">2888 Salmi Risto</a></td><td class=\"tasoitus\" style=\"border-top:2px solid #16B2B4;padding:0\"><a href=\"#\" class=\"painike painike-hae-muokattavaksi\"></a></td></tr>        <tr><td class=\"pisteet\" style=\"padding:0\"><a href=\"#\" class=\"painike painike-pisteet hae-muokattavaksi\" data-kilpailu=\"106\" data-kaavio=\"106\" data-kaaviokierros=\"11\" data-kaaviopaikka=\"59\" data-ab=\"B\" data-ottelu=\"181510\" data-muokattava=\"pisteet\"></a></td><td class=\"nimi\" style=\"padding:0\"><a href=\"#\" class=\"painike painike-hae-muokattavaksi hae-muokattavaksi\" data-kilpailu=\"106\" data-kaavio=\"106\" data-kaaviokierros=\"11\" data-kaaviopaikka=\"59\" data-ab=\"B\" data-ottelu=\"181510\" data-muokattava=\"nimi\">2893 Rantanen Mikko</a></td><td class=\"tasoitus\" style=\"padding:0\"><a href=\"#\" class=\"painike painike-hae-muokattavaksi\"></a></td></tr>        <tr><td class=\"pelimuoto\"><!-- a --><a href=\"#\" class=\"painike painike-pelimuoto hae-muokattavaksi\" data-kilpailu=\"106\" data-kaavio=\"106\" data-kaaviokierros=\"11\" data-kaaviopaikka=\"59\" data-ab=\"\" data-ottelu=\"181510\" data-muokattava=\"voittopisteet\"></a></td><td class=\"ajankohta\"><!-- b --><a href=\"#\" class=\"painike hae-muokattavaksi\" data-kilpailu=\"106\" data-kaavio=\"106\" data-kaaviokierros=\"11\" data-kaaviopaikka=\"59\" data-ab=\"\" data-ottelu=\"181510\" data-muokattava=\"biljardipoyta\">Pöytä -</a><a href=\"#\" class=\"painike hae-muokattavaksi\" data-kaavio=\"106\" data-kaaviopaikka=\"59\" data-pelitapa=\"aika\">Ei aikataulutettu</a></td><td class=\"toiminnot\"><!-- c --><a href=\"#\" class=\"painike painike-toiminnot-play hae-muokattavaksi\" data-kilpailu=\"106\" data-kaavio=\"106\" data-kaaviokierros=\"11\" data-kaaviopaikka=\"59\" data-ab=\"\" data-ottelu=\"181510\" data-muokattava=\"ottelualoitus\"></a></td></tr>');</script>";

1st, I didn't go further than the first mistake (in comments)

print "<script>alert('<tr><td class="pisteet" style="border-top:2px solid #16B2B4;padding:0">

-> just this line should throw an error

You really need to use a decent IDE :)

your code shows :

print "<script>document.getElementById('paikka59').innerHTML = '<tr>
<td class=\"pisteet\" style=\"border-top:2px solid #16B2B4;padding:0\"><!-- a --></td></tr>');</script>";

you should get rid of the extra ) at the end

when testing, throws a warning/error

See Element.innerHTML for different Syntax

EDIT: always check all of the stuff, especially looooong ones :)

double quotes are creating a problem here.

Your print string is getting terminated at

print "<script>alert('<tr><td class="     // rest all code will be skipped

Use \" in such situation. Your print statemnet will become like

print "<script>alert('<tr><td class=\"pisteet\" ...  </tr>');</script>";

One more thing, you can not add html tags inside alert(). You can only insert plaintext to alert(), confirm() and prompt() boxes.

Have a look at below thread : HTML Tags in Javascript Alert() method