簡體   English   中英

無法接收從html中的rest api傳遞的json響應

[英]Can't receive the json response being passed from rest api in html

Rest Api in能夠創建json,但是我的ajax無法接收從rest api傳遞的json內容。

function loadJsonData(){

    var dropDownValue = document.getElementById("dropdown").value;
    $.ajax({
        url:'http://localhost:8085/ParsingJson/rest/service/resources/getjsondata/'+dropDownValue,
        type:'get',
        contentType: 'application/json; charset=utf-8',
        cache:false,
        success:function(data){
        alert(data);
        document.getElementById("mySavedModel").value = data;
        load();
        },
        error:function(){alert('error');}
    }
);
}

Rest api響應代碼:

@RequestMapping(value = "/getjsondata/{dropDownValue}", method = RequestMethod.GET)
public ResponseEntity<DummyPojo>  getJsonData(@PathVariable String dropDownValue) throws ApplicationException, ParseException{

    System.out.println("In For Json Data:: " + dropDownValue);

    DummyPojo dp = new DummyPojo();
    dp.setAge("14");
    dp.setName("Cap");
    return new ResponseEntity<DummyPojo>(dp,HttpStatus.OK);
}

我想在我的html文件中使用JSON數據。

似乎有兩種可能性

  • dropDownValue為null OR
  • mySavedModel尚未加載

在調用loadJsonData之前,請確保已加載頁面DOM

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM