여기 내 코드에서 json 형식의 사용자 이름과 비밀번호를 json 형식으로 제공하여 편안한 서비스를 얻습니다. 이 메소드는 json의 두 텍스트 상자에 표시 할 수없는 json 객체를 반환합니다.jquery에서 json 객체 값 인쇄
여기 내 JSP 페이지이다 :
<script>
$(document).ready(function() {
$("#btnSubmit").click(function() {
var uname = $("#uname").val();
var pwd = $("#pwd").val();
authenticate(uname, pwd);
});
});
//authenticate function to make ajax call
function authenticate(uname, pwd) {
$.ajax
({
type: 'GET',
//the url where you want to sent the userName and password to
url: 'REST/WebService/GetLogin',
dataType: 'json',
async: false,
//json object to sent to the authentication url
data:{'uname': uname, 'pwd': pwd },
error:function()
{
alert("unsuccessfull");
},
success:function(server_response)
{
$('#message').text(server_response.message);
$('#lastname').text(server_response.lastname);
alert("successfull");
}
});
}
</script>
<input type="text" id="message"></input><br/>
<input type="text" id="lastname"></input><br/>
UserName:<input type="text" name="uname" id="uname"/><br/>
Password:<input type="text" name="pwd" id="pwd"/><br/>
<input type="submit" name="btnSubmit" id="btnSubmit" value="LogIn"/>
내 편안한 get 메소드 :이 피드
@Path("/WebService")
public class LoginService{
@GET
@Path("/GetLogin")
@Consumes("application/json")
@Produces("application/json")
public String loginFeed(@QueryParam("uname") String uname,@QueryParam("pwd") String pwd)
{
String feeds = null;
try
{
ArrayList<FeedObjects> feedData = null;
ProjectManager projectManager= new ProjectManager();
feedData=projectManager.GetLogin(uname, pwd);
feeds=FeedTransformer.UserFeed(feedData);
System.out.println("inside");
}
catch (Exception e)
{
System.out.println("error");
}
return feeds;
}
는 JSON 객체의 형태이다. 성공에
예외가 발생한 결과 대신에 어떤 결과가 나타 납니까? 오류가 있습니까? 파이어 폭스 플러그인 "Firebug"를 사용하면 네트워크 통신을 분석 할 수 있습니다. 이렇게하면 Firebug에서 JSON 결과를 볼 수 있습니다. 서버 부분에서 사용하는 헤더는 무엇입니까? JSON이 아닌 경우 결과가 JSON에 있음을 jQuery에 알리거나 'var server_message_json = $ .parseJSON (server_message);를 사용하려고 할 수 있습니다. ** 편집 : ** 실제로 ** ** 데이터 유형을 제출 했습니까? 어쨌든, 방화범은 두통으로 가득 찬 많은 수면 밤에서 당신을 구할 수 있습니다. –
내 응답은 편안한 서비스 구현 즉, @Produces ("application/json") – shanky