我想使用获取请求调用以下url。jquery:ajax获取请求不起作用
http://localhost:8080/abc/employees
当我在浏览器上面的URL打开,我得到以下答复。
[{ “名字”: “哈日克里希纳”, “ID”:1, “姓氏”: “Gurram”, “permAddrees”:{ “区域”: “Marthali”, “城市”:”班加罗尔“,”国家“,”印度“,”国家“,”卡纳塔克邦“,”tempAddrees“:{”area“:”Electronic City“,”city“:”Bangalore“,”country“ ,“state”:“Karnataka”}},{“firstName”:“PTR”,“id”:2,“lastName”:“PTR”,“permAddrees”:{“area”:“Bharath Nagar”城市“:”海得拉巴“,”国家“:”印度“,”国家“:”安得拉 Pradesh“},”tempAddrees“:{”area“:”BTM Layout“,”city“:”Bangalore“国家“:”印度“,”州“:”卡纳塔克邦“}}]
以下是我的jquery代码片段。
<!DOCTYPE html>
<html>
<head>
<script src = "jquery-3.1.0.js"></script>
</head>
<body>
<h1>Click the below button to see the AJAX response</h1>
<input type="submit" value="click here" id="button1" />
<div id="placeHolder">
</div>
<script type="text/javascript">
var jq = jQuery.noConflict();
jq(document).ready(function(){
jq("#button1").click(function(){
alert("Hello");
jq.get("http://localhost:8080/abc/employees", function(data, status){
alert(data + "" + status);
jq("#placeHolder").html(response);
});
});
});
</script>
</body>
</html>
当我按一下按钮,它显示第一个警告框“警报(‘你好’);”,但不执行回调函数的警告框。任何人都可以帮我找出我的代码问题。
当你调试这个,怎么专失败?服务器的回应是什么?有没有错误? – David
嗨大卫,添加屏幕截图,当你看到标题部分'内容长度是244'即将到来。但是当我去回复部分时,它是空的。 –
jquery的路径是否正确? 我检查过,它在Chrome中运行良好(在给出jQuery的路径之后)。 – cafebabe1991