How to fetch only data value using ajax
To fetch data from ajax response follow this......
$.ajax({
url: your_url,
success: function(req){
var data = new Array();
var pairs = req.split("&");
for (i = 0; (i < pairs.length); i++) {
var nameAndValue = pairs[i].split("=");
var name = unescape(nameAndValue[0]);
var value = unescape(nameAndValue[1]);
data[name] = value;
}
$("#startDate").val(data['startDate']);
$("#endDate").val(data['endDate']);
$("#comments").val(data['comment']);
$("#year").val(data['currentSession']);
}
});
set name value pair in your response in action class separated by any char. I just do with '&'
and u can fetch data by name. No need to set whole div. You just set value in your desired field and location.
eg:-- name1=value1&name2=value2&name3=value3 set in your ajax response. And fetch data like above.
$.ajax({
url: your_url,
success: function(req){
var data = new Array();
var pairs = req.split("&");
for (i = 0; (i < pairs.length); i++) {
var nameAndValue = pairs[i].split("=");
var name = unescape(nameAndValue[0]);
var value = unescape(nameAndValue[1]);
data[name] = value;
}
$("#startDate").val(data['startDate']);
$("#endDate").val(data['endDate']);
$("#comments").val(data['comment']);
$("#year").val(data['currentSession']);
}
});
set name value pair in your response in action class separated by any char. I just do with '&'
and u can fetch data by name. No need to set whole div. You just set value in your desired field and location.
eg:-- name1=value1&name2=value2&name3=value3 set in your ajax response. And fetch data like above.
Comments
Post a Comment