Jquery ajax call pass GridView DataKey
I need to pass a GridView DataKey (Primary key) as parameter in an ajax call JSON with jquery.
However,i dont't to expose my primary key column in source code HTML.I've already tried to hide the TD (first column) of the table,but it doenst hide in source code.
Here is the Jquery code:
$(function(){
$("tr").each(function(){//hide primary key columns in design
$("td:first",this).hide();
$("th:first",this).hide();
});
$("tr:not(:first)").click(function(){
$.ajax({
type:"POST",
url:"CRUDWeb.asmx/DeleteRow",
data:"{'duviID': '" + $(this).children("td:first").html() + "'}",//get primary key
contentType:"application/json; charset=utf-8",
dataType:"json",
success:function(){},
error:function(rh){alert(rh.responseText);}
});
})开发者_StackOverflow社区;
});
Any ideas?
You can't.
The primary key must be printed somewhere in the source code, else the jquery (client side) can't send the information to the ajax call.
The only solution is if there is another unique key you can print in your source code, then you can send this key to your script and lookup the Primary key.
精彩评论