ASP parameter is not passing to JavaScript

2020-05-03 11:44发布

问题:

Here is my ASP code

string studentid = dr["StudentId"].ToString();
        string studentname = dr["studentName"].ToString();
        Response.Write("<tr>");
        Response.Write("<td id = 'sid' >");
        Response.Write(studentid);
        Response.Write("</td>");
        Response.Write("<td>");
        Response.Write(studentname);
        Response.Write("</td>");
        Response.Write(String.Format("<td id = '{0}' onclick = 'update({0})' >", studentid));
        Response.Write("<img src = 'Edit-icon.png' height='20' width='20' >");
        Response.Write("</td>");
        Response.Write(String.Format("<td id = '{0}' onclick = 'deleteStudent({0})' >", studentid));
        Response.Write("<img src = 'ic_delete_48px-128.png' height='20' width='20'>");
        Response.Write("</td>");
        Response.Write("</tr>");
    }

whenever I'm clicking on td id="studentid" the JavaScript function is being called but the parameter is not passing. Here is my JavaScript function:

function deleteStudent(x) {

        alert(x);
        var ajaxRequest = new XMLHttpRequest;
        ajaxRequest.open("GET", "crudops.aspx?StudentId=" + x +"&operation=delete", false);
        ajaxRequest.send(null);
        ...

Here alert(x) is saying [object HTMLCollection] What's the problem? Help me out with suggestions.