jQuery.parseJSON 未完成 Ajax 成功
jQuery.parseJSON not working on Ajax Success
我正在尝试解析我作为响应收到的 json 数据,但使用 jQuery.parseJSON 它不起作用。
Ajax 如果我从 Ajax 成功回调函数
的评论中删除以下数据,则成功不起作用
$(document).ready(function(){
//Working Example in Comment
//var obj = jQuery.parseJSON( '{ "name": "harsh","address":["add1","add2"] }' );
//var objArray = obj.address;
//alert(objArray[2]);
$('#getData').click(function(){
$.ajax({
url:'JsonServlet',
type:'post',
dataType: 'json',
success: function(data) {
//var JSONdata = jQuery.parseJSON(data);
//alert(JSONdata);
$('#name').val(data.name);
$('#email').val(data.email);
$("#add").val(data.innerJSONObj1.address);
}
});
});
});
由于您指定了数据类型:'json',数据变量已经是一个 json 对象。
http://api.jquery.com/jquery.ajax/
If json is specified, the response is parsed using jQuery.parseJSON before being passed, as an object, to the success handler. The parsed JSON object is made available through the responseJSON property of the jqXHR object.
我正在尝试解析我作为响应收到的 json 数据,但使用 jQuery.parseJSON 它不起作用。 Ajax 如果我从 Ajax 成功回调函数
的评论中删除以下数据,则成功不起作用$(document).ready(function(){
//Working Example in Comment
//var obj = jQuery.parseJSON( '{ "name": "harsh","address":["add1","add2"] }' );
//var objArray = obj.address;
//alert(objArray[2]);
$('#getData').click(function(){
$.ajax({
url:'JsonServlet',
type:'post',
dataType: 'json',
success: function(data) {
//var JSONdata = jQuery.parseJSON(data);
//alert(JSONdata);
$('#name').val(data.name);
$('#email').val(data.email);
$("#add").val(data.innerJSONObj1.address);
}
});
});
});
由于您指定了数据类型:'json',数据变量已经是一个 json 对象。
http://api.jquery.com/jquery.ajax/
If json is specified, the response is parsed using jQuery.parseJSON before being passed, as an object, to the success handler. The parsed JSON object is made available through the responseJSON property of the jqXHR object.