How to pass hidden value to ajax ?
How to pass hidden value to ajax ?
Hi,
I am trying to pass data value Ihidden in datatable) from jsp to js file :
[code]
Edit
[/code]
js file :
[code]
$('#metadataListTable input.delete').live('click', function() {
// alert("attached delete");
var ans = confirm("Do you want to delete agency?");
if(ans==true){
var nRow = $(this).parents('tr')[0];
var ifaceData = $("#ifaceData").val();
alert(ifaceData); // This alert display undefined <-------------------
oTable.fnDeleteRow(nRow);
$.ajax({
url: "deleteMetadata.do",
data: "id=" + nRow.id + "&flag=" + "T" + "&ifaceData=" + ifaceData,
success: function(response) {
alert("response from the action : " + response);
}
})
}
});
[/code]
Please your help is appreciated.
I am trying to pass data value Ihidden in datatable) from jsp to js file :
[code]
Edit
[/code]
js file :
[code]
$('#metadataListTable input.delete').live('click', function() {
// alert("attached delete");
var ans = confirm("Do you want to delete agency?");
if(ans==true){
var nRow = $(this).parents('tr')[0];
var ifaceData = $("#ifaceData").val();
alert(ifaceData); // This alert display undefined <-------------------
oTable.fnDeleteRow(nRow);
$.ajax({
url: "deleteMetadata.do",
data: "id=" + nRow.id + "&flag=" + "T" + "&ifaceData=" + ifaceData,
success: function(response) {
alert("response from the action : " + response);
}
})
}
});
[/code]
Please your help is appreciated.
This discussion has been closed.
Replies
[code]$("#form1").submit(function(event){
event.preventDefault();
var str = $(this).serialize(); //Contains the data from all input fields in the form
$.ajax({
url:"deleteMetadata.do",
type:"post",
data: str,
success:function(response){
alert("response from the action : " + response);
}});
});[/code]
This way, whatever is in the hidden field is included in [code]var str[/code]
or, you could pass your variable like this:
[code]var ifaceData = $("#ifaceData").val();
$.ajax({
url:"deleteMetadata.do",
type:"post",
data: {submitThis:ifaceData},
success:function(response){
alert("response from the action : " + response);
}}); [/code]
I have had trouble trying to build a data string within the AJAX call, using the [code]variable="somedata"&variable2="moredata"[/code] format. If you want to go that way, build it in a variable before you call AJAX, and pass that variable as the data.
I hope this helps. Good luck.
I have a question, if I use :
var str = $(this).serialize();
do I have to parse it in the server side to get each data that was submitted in the form ?
Thanks