jQuery Cross Domain Ajax

前端 未结 7 1930
Happy的楠姐
Happy的楠姐 2020-12-09 05:06

My ajax code is

$.ajax({
    type: \'GET\',
    dataType: \"jsonp\",
    processData: false,
    crossDomain: true,
    jsonp: false,
    url: \"http://someo         


        
7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-09 05:41

    Here is the snippets from my code.. If it solves your problems..

    Client Code :

    Set jsonpCallBack : 'photos' and dataType:'jsonp'

     $('document').ready(function() {
                var pm_url = 'http://localhost:8080/diztal/rest/login/test_cor?sessionKey=4324234';
                $.ajax({
                    crossDomain: true,
                    url: pm_url,
                    type: 'GET',
                    dataType: 'jsonp',
                    jsonpCallback: 'photos'
                });
            });
            function photos (data) {
                alert(data);
                $("#twitter_followers").html(data.responseCode);
            };
    

    Server Side Code (Using Rest Easy)

    @Path("/test_cor")
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String testCOR(@QueryParam("sessionKey") String sessionKey, @Context HttpServletRequest httpRequest) {
        ResponseJSON resp = new ResponseJSON();
        resp.setResponseCode(sessionKey);
        resp.setResponseText("Wrong Passcode");
        resp.setResponseTypeClass("Login");
        Gson gson = new Gson();
        return "photos("+gson.toJson(resp)+")"; // CHECK_THIS_LINE
    }
    

提交回复
热议问题