0

I have syntax error in my script.js file on line 38, here is my javascript code. i used PHP ajax and javascript to repeat table rows.also i used html table tag to display news and i am going to make a newsletter thorugh php including mysql database.

$(document).ready(function(){
$("#save").click(function(){
    ajax("save");
});

$("#add_new").click(function(){
    $(".entry-form").fadeIn("fast");    
});

$("#close").click(function(){
    $(".entry-form").fadeOut("fast");   
});

$("#cancel").click(function(){
    $(".entry-form").fadeOut("fast");   
});

$(".del").live("click",function(){
    ajax("delete",$(this).attr("id"));
});

function ajax(action,id){
    if(action =="save")
        data = $("#userinfo").serialize()+"&action="+action;
    else if(action == "delete"){
        data = "action="+action+"&item_id="+id;
    }

    $.ajax({
        type: "POST", 
        url: "ajax.php", 
        data : data,
        dataType: "json",
        success: function(response){
            if(response.success == "1"){
                if(action == "save"){
                    $(".entry-form").fadeOut("fast",function(){
                        $(".table-list").append(""+response.fname+""+response.lname+""+response.email+""+response.phone+"<a id="+response.row_id+" class="del" href="#">Delete</a>");   
                        $(".table-list tr:last").effect("highlight", {
                            color: '#4BADF5'
                        }, 1000);
                    }); 
                }else if(action == "delete"){
                    var row_id = response.item_id;
                    $("a[id='"+row_id+"']").closest("tr").effect("highlight", {
                        color: '#4BADF5'
                    }, 1000);
                    $("a[id='"+row_id+"']").closest("tr").fadeOut();
                }
            }
        },
        error: function(res){
            alert("Unexpected error! Try again.");
        }
    });
}

});

2
  • The syntax error is in the line $(".table-list").append(""+response.fname+""+response.lname+""+response.email+""+response.phone+"<a id="+response.row_id+" class="del" href="#">Delete</a>");, escape quotes or use single quotes Commented Sep 10, 2015 at 5:54
  • You may want to know that .live() has long since been deprecated is even removed from later versions of jQuery. The delegated form of .on() is used to replace it. Commented Sep 10, 2015 at 5:59

3 Answers 3

2

The problem -> A mixture of "" and ''

Solution:-

 $('.table-list').append(""+response.fname+""+response.lname+""+response.email+""+
    response.phone+"<a id="+response.row_id+" class='del' href='#'>Delete</a>");

Notice, changed class="del" href="#" to class='del' href='#' and $(".table-list") to $('.table-list') (although that's not that important).

Sign up to request clarification or add additional context in comments.

Comments

0

You can use console of developer tools in chrome and for firefox use firebug console.

Comments

0

Removed your errors

 $(".table-list").append(""+response.fname+""+response.lname+""+response.email+""+response.phone+"<a id="+response.row_id+"class="+del+"href=#>Delete</a>");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.