0

the problem was in the line

  $('<td></td>').val(item['id']).html(
        '<a href="edit.html?id'='+sid'">Edit</a>'),alert(sid+"Id2:"+item['id']),
                            

here the alert is getting clearly.. but in browser the path shows

//localhost:8080/sample/teacher/edit.html?id'=sid'

here not shows the value of sid that is id 41 i want to show the link as

localhost:8080/sample/teacher/edit.html?id=41 or any other dynamic id value

i don't know why this happen the code is not right

Here var sid is an array & push value id to array.. the alert shows the value of sid & item['id'] correctly.

   $.each(responseData, function(index, item) {

        var sid = [];
                                
        $('#student').append(           
        $('<td></td>').val(item['id']).html(
            item['name']), 
    
        $('<td></td>').val(item['id']).html(
            item['phoneNo']),

            sid.push(item['id']),

        $('<td></td>').val(item['id']).html(
            '<a href="edit.html?id'='+sid'">Edit</a>'),alert(sid+"Id2:"+item['id']),

        $('<td></td>').val(item['id']).html(
                '<button onclick="lightbox1_open();">Delete</button>'),
        $('<br />').val(item['id']).html(
            item['']));         
        
    });

if you know the answer please share here...

3 Answers 3

3

Looks like the string concatenation is the problem, try

$('<td></td>').val(item['id']).html('<a href="edit.html?id=' + sid + '">Edit</a>')
Sign up to request clarification or add additional context in comments.

4 Comments

i got an error when change the code Field error in object 'student' on field 'id': rejected value [' sid ']; codes [typeMismatch.student.id,typeMismatch.id,typeMismatch.long,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [student.id,id]; arguments []; default message [id]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'long' for property 'id'; nested exception is java.lang.NumberFormatException: For input string: "'sid'"]
what is the value of sid
the sid value is dynamic value it's change example 41
the browser shows the link as /teacher/edit.html?id=' + sid + '
2

change id'='+sid'" this by id='+sid+'"

$('<td></td>').val(item['id']).html('<a href="edit.html?id=' + sid +'">Edit</a>');

Comments

2

Use like this

'<a href="edit.html?id=' + sid + '">Edit</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.