Reputation: 13
i am calling this UpdateItem function using ajax, using achor tag . it gave me console error
Error : req is undefined
function updateItem(id, desc, vehicleno){
alert("i am here");
$('#ProcessModal').modal('show');
$('#<%=txtPartNo.ClientID%>')[0].value=id;
$('#<%=txtPartNo.ClientID%>')[0].value=partno;
}
Ajax calling ...
......
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "<%=BasePath%>/WebServices/RequisitionService.asmx/GetAllRequisitionItems",
data: '{ ReqID: "<%=_RecordId%>"}',
dataType: "json",
success: function (data) {
var req=[];
var desc=[];
var veh=[];
for (var i = 0; i < data.d.length; i++) {
req[i] =data.d[i].RequisitionItemsID;
desc[i]= data.d[i].ItemDescription;
veh[i]= data.d[i].VehicleNumber;
$("#reqTable").append("<tr><td>"+data.d[i].PartNo + "</td><td>" + data.d[i].ItemDescription +"</td><td>"+data.d[i].Quantity+"</td><td>"+data.d[i].VehicleNumber+"</td><td> " + data.d[i].ItemStatus +"</td><td>"+ data.d[i].Remarks+"</td><td><a href='javascript:updateItem(req[i], desc[i], veh[i] );'>Process</a> </td></tr>");
}
},
error: function (result) {
},
});
....
Upvotes: 0
Views: 173
Reputation: 26
Actually its quite easy , you have done nothing wrong except the quotation marks.. kindly correct them as follow , it will work.
At declaration:
var req='';
var desc='';
ar veh='';
and in your function where you require these variables.
<a href='javascript:updateItem(\"" + req + "\", \"" + desc + "\",\"" + veh + "\" );' <%= (ReqStage == (int)RequisitionStage.PendingforHOApproval) ? "" : "style=display:none" %>>Process</a> </td></tr>");
Hope it helps Happy Coding :)
Upvotes: 1
Reputation: 514
use JavaScript Array push() Method. Like -
req.push(data.d[i].RequisitionItemsID);
desc.push(data.d[i].ItemDescription);
veh.push(data.d[i].VehicleNumber);
Upvotes: 0