I am trying this to get json object but it does not seem to work
$.post("/csm/compare.action",
{
sessiontoken: sessiontoken,
compareCategory: "system",
compareSubCategory:"patch",
xml1:absP[0],
xml2:absP[1]},
function(data)
{
alert(data.response[0].elementName);
}
);
Part of my json that gets returned
{
"response": [
{
"id": "0",
"elementName": "Accounting.ACCT-ENG-A-MAN",
"subCategory": "patch",
"isEqual": false,
"isPrasentinXml1": true,
"isPrasentinXml2": true,
"attribute": [
{
"name": "information",
"firstValue": "Acco",
"secondValue": "Acco"
},
{
"name": "name",
"firstValue"开发者_如何学C: "Accounting.ACCT-ENG-A-MAN",
"secondValue": "Accounting.ACCT-ENG-A-MAN"
},
{
"name": "version",
"firstValue": "B.11.23",
"secondValue": "B.11.23"
}
]
}
]
}
try
$.post("/csm/compare.action",
{
sessiontoken: sessiontoken,
compareCategory: "system",
compareSubCategory:"patch",
xml1:absP[0],
xml2:absP[1]},
function(data)
{
data = $.parseJSON(data);
alert(data.response[0].elementName);
}
);
$.post('"/csm/compare.action"',
{
sessiontoken: sessiontoken,
compareCategory: "system",
compareSubCategory:"patch",
xml1:absP[0],
xml2:absP[1]},
function(data){
alert(data);
alert(data.response[0].elementName);
}, 'json');
not sure whether it'll help or not but you can try it anyway also if you use $.ajax
instead of post
you can make an error
call back that will give a more insight
try this if the above fails
$.post("/csm/compare.action",
{
sessiontoken: sessiontoken,
compareCategory: "system",
compareSubCategory:"patch",
xml1:absP[0],
xml2:absP[1]},
function(data)
{
data = JSON.parse(data); <-- the change is here
alert(data);
alert(data.response[0].elementName);
}
);
the ajax equivalent is
$.ajax({
url:'/csm/compare.action',
type:'POST',
data:{
sessiontoken: sessiontoken,
compareCategory: "system",
compareSubCategory:"patch",
xml1:absP[0],
xml2:absP[1]
},
cache:false,
success:function(data){
data = JSON.parse(data);
alert(data);
},
error:function(jqxhr){
alert(jqxhr.status);
alert(jqxhr.responseText);
}
});
精彩评论