$.ajax 求助
本帖最后由 水瓶座 于 2019-1-24 21:12 编辑<!DOCYTPE HTML>
<html>
<head>
<meta charset="utf-8" />
<link rel="icon" href="../favicon.ico" type="image/x-icon"/>
<title>标题</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
function seach(){
var content = document.getElementById("content");
$.ajax(
type: "post",
url: "http://app.91fuyun.com:8787/service/rest",
data:{
"apiVersion":"v1",
"params":content.value,
"app_version":"3",
"api":"cartoon.search"
},
contentType: 'application/x-www-form-urlencoded;charset=utf-8',
complete: function(xhr,status){
alert(status);
},
error: function(xhr,status,error){
alert(error);
},
success: function(data,status,xhr){
alert(status);
},
dataType:"text");
alert(content.value);
$(".all").html("预备,各就位!");
}
</script>
</head>
<body>
<div class="all">
<div class="seach">
<input type="text" value="" id="content">
<button type="button" onclick="seach()">搜索</button>
</div>
<div class="choose">
</div>
<div class="show">
</div>
</div>
</body>
</html>
要么发不了请求,要么不执行回调函数。实在没辙了!!!
求大佬解决! 代码没问题,鱼油请求的服务器没法用哈:
不二如是 发表于 2019-1-25 09:57
代码没问题,鱼油请求的服务器没法用哈:
不会吧!见图1
虽然这个post的地址是我随便找的
这次,换了data,望大佬继续帮忙看看,它是真的没反应,见图2
证明这地址没问题,见图3
修改后,只动了post的data和input的value:
<!DOCYTPE HTML>
<html>
<head>
<meta charset="utf-8" />
<link rel="icon" href="../favicon.ico" type="image/x-icon"/>
<title>标题</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
function seach(){
var content = document.getElementById("content");
$.ajax(
type: "post",
url: "http://app.91fuyun.com:8787/service/rest",
data:{
"apiVersion":"v1",
"params":content.value,
"app_version":"3",
"api":"cartoon.getcartoon"
},
contentType: 'application/x-www-form-urlencoded;charset=utf-8',
complete: function(xhr,status){
alert(status);
},
error: function(xhr,status,error){
alert(error);
},
success: function(data,status,xhr){
alert(status);
},
dataType:"text");
alert(content.value);
$(".all").html("预备,各就位!");
}
</script>
</head>
<body>
<div class="all">
<div class="seach">
<input type="text" value="198" id="content">
<button type="button" onclick="seach()">搜索</button>
</div>
<div class="choose">
</div>
<div class="show">
</div>
</div>
</body>
</html> 水瓶座 发表于 2019-1-25 12:00
不会吧!见图1
虽然这个post的地址是我随便找的
ajax() 方法用于执行 AJAX(异步 HTTP)请求。
所有的 jQuery AJAX 方法都使用 ajax() 方法,该方法通常用于其他方法不能完成的请求。
语法:
$.ajax({name:value, name:value, ... })
鱼油(报错哈,缺少"{}"):
$.ajax(
type: "post",
url: "http://app.91fuyun.com:8787/service/rest",
data:{
"apiVersion":"v1",
"params":content.value,
"app_version":"3",
"api":"cartoon.getcartoon"
},
contentType: 'application/x-www-form-urlencoded;charset=utf-8',
complete: function(xhr,status){
alert(status);
},
error: function(xhr,status,error){
alert(error);
},
success: function(data,status,xhr){
alert(status);
},
dataType:"text"
);
修改:
<!DOCYTPE HTML>
<html>
<head>
<meta charset="utf-8" />
<link rel="icon" href="../favicon.ico" type="image/x-icon"/>
<title>标题</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
function seach(){
var content = document.getElementById("content");
$.ajax({
type: "post",
url: "http://app.91fuyun.com:8787/service/rest",
data:{
"apiVersion":"v1",
"params":content.value,
"app_version":"3",
"api":"cartoon.getcartoon"
},
contentType: 'application/x-www-form-urlencoded;charset=utf-8',
complete: function(xhr,status){
alert(status);
},
error: function(xhr,status,error){
alert(error);
},
success: function(data,status,xhr){
alert(status);
},
dataType:"text"
});
alert(content.value);
$(".all").html("预备,各就位!");
}
</script>
</head>
<body>
<div class="all">
<div class="seach">
<input type="text" value="198" id="content">
<button type="button" onclick="seach()">搜索</button>
</div>
<div class="choose">
</div>
<div class="show">
</div>
</div>
</body>
</html>
代码可以跑通了哈,只是请求不到数据(需要你重新设计):
本帖最后由 水瓶座 于 2019-1-25 17:13 编辑
不二如是 发表于 2019-1-25 14:10
ajax() 方法用于执行 AJAX(异步 HTTP)请求。
所有的 jQuery AJAX 方法都使用 ajax() 方法,该方法通 ...
确实是语法错误,谢谢大佬!
{"code":200,"data":{"id":"198","title":"\u6d17\u8111\u65c5\u9986","summary":"ps:\u76f8\u540c\u7ae0\u8282\u4e0d\u4f1a\u91cd\u590d\u6d88\u8017\u94bb\u77f3","update_desc":"\u5b8c\u7ed3","author":"\u7f51\u53cb\u4e0a\u4f20","pic_url":"http:\/\/pm.cnsunp.com\/lifanacgup\/lifanacg\/20170623\/1\/0.jpg","cartooncol":null,"score":"0","collect":"0","status":"1","class_id":"5","create_time":"2018-07-17 ","modified_time":"2018-07-17 ","update_time":"2018-07-17 ","weight":"0","detail":[{"no":1,"title":"\u7b2c\u4e00\u7ae0","cost":0},{"no":2,"title":"\u7b2c\u4e8c\u7ae0","cost":0},{"no":3,"title":"\u7b2c\u4e09\u7ae0","cost":0}],"is_hot":"0","hot_pic":"","tags":"\u5168\u5f69,\u6f2b\u753b","fav_count":"8340","pay":"0","cost_start":"-1","cost_amount":null,"sale_start_time":null,"sale_end_time":null,"sale_cost_amount":null,"sell_total_amount":null,"sell_total_user_count":null,"newest_chapter_no":"0","spider_name":null,"rank_recom":"0","rank_collect":"0","rank_fin":"0","rank_new":"0","rank_o1":"0","is_fin":"0","sound_read":1},"message":"OK","list_size":20}
服务器返回了,都是这样的也不知道算什么类型。
我百度过,说json的话要在每个"号前加上\转义。
可服务器是别人的...{:10_245:} 所以不能让世界适应我们,只能我们去适应世界。
改成dataType:"text"也是如此
扯多了,一句话。没法子了,就问问大佬有没有什么办法? 本帖最后由 不二如是 于 2019-1-25 17:38 编辑
水瓶座 发表于 2019-1-25 17:12
确实是语法错误,谢谢大佬!
简单数据,直接“循环遍历”获取,复杂操作只能用正则去筛数据了哈 不二如是 发表于 2019-1-25 17:35
简单数据,直接“循环遍历”获取,复杂操作只能用正则去筛数据了哈
不,我的意思是收不到数据,或者说一直不进success里,要怎么写才能让它进success而不是error 不二如是 发表于 2019-1-25 17:35
简单数据,直接“循环遍历”获取,复杂操作只能用正则去筛数据了哈
好了,搜到了,因为同源策略,所以不用弄了,谢谢大佬!
页:
[1]