자바 스크립트에 문제가 있습니다. 나는이 같은 AG-그리드 JSON 배열을로드하기 위해 노력하고있어 나는 단순히 JSON 파일에서 JSON로드 해요 때문에 아래 잘 작동 : 나는 다음과 같은 방법으로 그것을 할자바 스크립트에서 json을로드하는 중 오류가 발생했습니다.
var httpRequest = new XMLHttpRequest();
httpRequest.open('GET', '../dist/output.json');
httpRequest.send();
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState == 4 && httpRequest.status == 200) {
var httpResult = JSON.parse(httpRequest.responseText);
function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
var parsedData = httpResult.map(function(obj) {
return Object.keys(obj).reduce(function(memo, key) {
var value = obj[key];
memo[key] = isNumeric(value) ? Number(value) : value;
return memo;
}, {})
})
그러나, (즉, 하는 JSP에서 JSON 배열을 받고, CONSOLE.LOG (jsonArray)는 잘 표시하지만 내가 얻을 오류 :
var jsonArray = document.getElementById("jsonArray");
console.log(jsonArray);
var httpRequest = new XMLHttpRequest();
httpRequest.open('GET', jsonArray);
httpRequest.send();
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState == 4 && httpRequest.status == 200) {
var httpResult = JSON.parse(httpRequest.responseText);
function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
var parsedData = httpResult.map(function(obj) {
return Object.keys(obj).reduce(function(memo, key) {
var value = obj[key];
memo[key] = isNumeric(value) ? Number(value) : value;
return memo;
}, {})
})
나는 다음과 같은 오류 얻을 :
Failed to load resource: the server responded with a status of 404 (Not Found)
어떻게 그렇게 첫 번째 코드를 변경을 나는 json에서 올바르게 읽을 수있다. 배열, 모든 json 데이터가 있습니다.
UPDATE :
jsonArray이는 JSP에서 다음과 같다 :
JSONArray jsonArray = new JSONArray(orderDetailsList1);
<input type="hidden" value="<%out.println(jsonArray);%>" id="jsonArray"/>
이유 : 그
value
속성은value
속성을 사용하여 액세스하려면? URL이 잘못되었습니다. 어떻게 고치는 지? 적절한 URL을 찾아냅니다. –'# jsonArray' 엘리먼트는 무엇입니까? –
@MarcB 어떤 URL을 사용합니까? – Shek