现在的位置: 首页 > 综合 > 正文

ajax跨域问题小结

2017年12月27日 ⁄ 综合 ⁄ 共 1283字 ⁄ 字号 评论关闭
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/),那么配置就需要跟它保持一致;

抱歉!评论已关闭.