加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ajax跨域问题小结

发布时间:2020-12-16 00:24:23 所属栏目:百科 来源:网络整理
导读:function ajaxChangePage(){ var prov = $("#prov").val(); var pageIndex = $("#pageIndex").val();//下一页就是第二页//alert('当前pageindex:'+pageIndex);var ip = '%=Global.getProperty("tianyiClub_ip") %';//alert(ip);$.ajax({data:$("#theForm").s
function ajaxChangePage(){
            	var prov = $("#prov").val();
            	var pageIndex = $("#pageIndex").val();//下一页就是第二页
				//alert('当前pageindex:'+pageIndex);
				var ip = '<%=Global.getProperty("tianyiClub_ip") %>';
				//alert(ip);
				$.ajax({
					data:$("#theForm").serialize(),url: ip + "/tianyiClub/changePage.jspx",type: 'POST',dataType: 'JSON',timeout: 5000,error: function() { alert('翻页失败!'); },success: function(msg) {
						//记下当前是第几页了
						$("#pageIndex").attr("value",(pageIndex-0+1));//很奇怪,直接+1居然变成11;
						//alert("翻页后pageIndex"+$("#pageIndex").val());
						
						//alert(eval(msg));
						if(null == eval(msg)){
							$("#up-refresh").attr("style","display:none");

							$("#sp1").attr("style","display:block");
							setTimeout(function() {
								$("#sp1").attr("style","display:none");
							},1000);

							return;
						}
						$.each(eval(msg),function(i,item) {
							//alert(item.URL);
							var msg = "<li><a href='"+item.url+"'><div class='new-list-l'><img src='${basepath }"+item.uploadaddress+"'></div><div class='new-list-r'><h2 class='h2-font'>"+item.title+"</h2><p>"+substrStr(item.introduce)+"</p><span class='tag'><img src='"+item.sLogo+"' /></span></div></a></li>";
							$("#list_main").append(msg);
	                    }); 
					}
				});            
            }



众所周知:ajax在请求一路action的时候,需要指明action的地址,就这个地址楼主用不同的ip去访问的时候后,提示:


这里有个global.getproperty("tianyiClub_ip"),以localhost举例,


设置:ip为127.0.0.1 响应“翻页失败”


这是ip为机器的ip 172.172.3.164 响应“翻页失败”


设置为localhost,成功返回数据;



结论:当前服务器访问的是什么路径(localhost:8080/),那么配置就需要跟它保持一致;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读