1

Hi i developed a web service that based on jersey 1.8 restful . when i invoked webservice from browser like http://localhost:8080/EC/EC/loginValidate/epicSearch/IVE0016808 i got output like

{"name":"Aneel Kumar Ravula","pollingStationLocation":"MARRIPALLI MPP SCHOOL","gender":"male","age":23,}

But when i invoked from jquery ajax it fails and controll at error function.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script>


$(document).ready(function() {
            // fetch some more records from the server side
            $.ajax({
                type: "GET",
                contentType: "json",
                url: "http://localhost:8080/EC/EC/loginValidate/epicSearch/IVE0016808",
                success: function(){alert('sucess by anil')},
                error: function(event){alert('fail by anilevent '+event)}
            });

    });
</script>
</HEAD>

<BODY>
</BODY>
</HTML>

now this is my latest code how to get response

$(document).ready(function() {
jQuery.support.cors = true;
            // fetch some more records from the server side
            $.ajax({
                type: "GET",
                dataType : "JSON",
                url: "http://localhost:8080/EC/EC/loginValidate/epicSearch/IVE0016808",
                crossDomain : true ,
                success: function(resp){alert('sucess by anil'+resp)},
                error: function(jqXHR, testStatus, errorThrown){alert('fail by anilevent '+errorThrown)}
            });

    });
4

1 回答 1

2

This is what I think your ajax call should look like

$(document).ready(function() {
        jQuery.support.cors = true;

        // fetch some more records from the server side
        $.ajax({
            type: "GET",
            dataType: "json",
            url: "http://localhost:8080/EC/EC/loginValidate/epicSearch/IVE0016808",
            success: function(data){alert('sucess by anil: ' + data.name)},
            error: function(jqXHR, textStatus, errorThrown){alert('fail by anilevent '+errorThrown)}
        });

});
于 2013-07-10T18:21:33.110 回答