2016-09-21 2 views
1

Ich habe eine Unexpected token }, aber ich weiß nicht warum.Uncaught SyntaxError: Unerwartetes Token} mit unbekanntem Grund

enter image description here

Es ist eine Tabelle mit einigen Tasten auf sie. Wenn Sie auf die Schaltfläche klicken, wird die Funktion Javascript aufgerufen.

Hier ist mein Code:

<tbody> 
<?php $i = 0; foreach ($query as $row){?> 
<tr> 
    <td><?php echo ++$i; ?></td> 
    <td><?php echo $row['address'] . ", " . $row['city'] . ", " . $row['state'] . ", " . $row['country']; ?></td> 
    <td> 
     <button id ="delete" class = "delete" type="button" value=<?php echo "\"" . $row['id'] . "\""; ?> onClick="deleteAddress(this.value)">delete</button> 
    </td> 
    <td> 
    //Print this <button id = "edit" class = "edit" type="button" value="7" onClick = "editAddress(this.value, "23", "323", "323", "iij")" >Edit</button> 
     <button id = "edit" class = "edit" type="button" value=<?php echo "\"" . $row['id'] . "\""; ?> onClick = <?php echo "\"editAddress(this.value" . ", \"" . trim($row['address']) . "\", \"" . $row['city'] . "\", \"" . $row['state'] . "\", \"" . $row['country'] . "\")\""; ?> >Edit</button></td> 
    </tr> 
</tbody> 

function editAddress(id, address, city, state, country) 
{ 
    document.getElementById("address_field").value = address; 
    document.getElementById("city_field").value = city; 
    document.getElementById("state_field").value = state; 
    document.getElementById("country_field").value = country; 
    document.getElementById("add_new").innerHTML = 'Update Address'; 
    document.getElementById("add_new").value = id; 
    document.getElementById("add_new").onclick = function() { 
     var id = document.getElementById("add_new").value; 
     var address = document.getElementById("address_field").value; 
     var city = document.getElementById("city_field").value; 
     var state = document.getElementById("state_field").value; 
     var country = document.getElementById("country_field").value; 

     jQuery.ajax({ 
      type: "POST", 
      url: "../wp-content/plugins/add_address_list/insert_address.php", 
      data: {functionName : "updateAddress", id : id, address : address, city : city, state : state, country : country}, 
      success: function(msg){ 
       window.location.reload(); 
      } 
     }); 
    }; 
    }     

Die IDE keine Syntaxfehler haben. Ich weiß nicht warum. Danke.

+1

Kommt der Fehler von PHP oder JavaScript, ist es nicht wirklich klar? Sie haben mehrere Syntaxfehler, zum Beispiel 'onClick = "editAddress (this.value," 23 "," 323 "," 323 "," iij ")" 'funktioniert nicht, da Sie doublequotes um die Argumente im Gleichzeitig verwenden Sie doublequotes für das Attribut. – adeneo

+0

Thx. Die Doublequotes wurden in Singlequotes geändert, dann funktioniert es jetzt. Vielen Dank. – Capslock10

Antwort

1

Es Fehler sind in:

onClick = "editAddress(this.value, "23", "323", "323", "iij")" 

Oder besser gesagt:

onClick = <?php echo "\"editAddress(this.value" . ", \"" . trim($row['address']) . "\", \"" . $row['city'] . "\", \"" . $row['state'] . "\", \"" . $row['country'] . "\")'"; ?> >Edit</button> 

das sein sollte:

<button id = "edit" class = "edit" type="button" value=<?php echo "\"" . $row['id'] . "\""; ?> onClick ='<?php echo "editAddress(this.value" . ", \"" . trim($row['address']) . "\", \"" . $row['city'] . "\", \"" . $row['state'] . "\", \"" . $row['country'] . "\")"; ?> >Edit</button></td> 

einfach die JavaScript mit ' so doppelten Anführungszeichen umschließen erlaubt sind, so dass es würde aussehen wie:

onClick = 'editAddress(this.value, "23", "323", "323", "iij")' 
+0

Geändert die Doppelquotes zu singlequotes, Und es funktioniert. Vielen Dank! – Capslock10

0

Sie haben vergessen zu einfach Ihre foreach-Schleife Schließen Sie mit "}" ;-)

setzen nur

<?php } ?> 

nach dem Schließen TR ... arbeiten, dass sollte.

+0

Ich habe vergessen, hier zu kopieren. LOL – Capslock10

+0

oh .. haha ​​.. ok .. – victor

Verwandte Themen