论坛首页 Web前端技术论坛

一个静态页面AJAX 读取服务器上的数据的问题

浏览 5007 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2012-12-24  
写的页面如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>VIP会员中心-{$SiteName}</title>
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<link href="style.css" rel="stylesheet" type="text/css">

<script src="jquery.js" type="text/javascript"></script> 
<script language="javascript" type="text/javascript">
    $(document).ready(function() {
        $("#btnSubmit").click(function() {
            Search();
        });
    });
    function Search() {
        $.ajax({
            type: "POST",
            url: "http://118.122.89.217:8808/ANBOSS/productView.c?do=queryProduct",
            data: {barCode: $("#barCode").val()},
			dataType : "jsonp",
			jsonp: "callback",
			timeout: '10000',
            beforeSend:function(){
				$("#msg").html("正在查询中,请稍候.....");
            },
            success:function(data){
				if(data!=null&&data!=''){
					var product = eval(data)[0];
					$("#msg").html('<h3>您好,您查询的产品结果如下:</h3><div class=hot>'+'商品名称:'+product[0]+';条码:'+product[1]+';证书号:'+product[2]+';产品类型:'+product[3]+';标签价:'+product[4]+';金重:'+product[5]+';主石重:'+product[6]+'</div><h3>感谢您对爱恋珠宝的支持!</h3>');
				}
				else{$("#msg").html("抱歉,您输入的产品条形编码(证书号)有误!");}
            },
            error:function(){
				$("#msg").html("error");
            }
        });
    }
</script>
<style>
.search #barCode{ width:265px; height:26px; border:1px solid #5d3c2b; line-height:26px; padding-left:3px; background:none;}
.search #btnSubmit{ border:0; width:56px; height:30px; background: url(img/search.gif); text-indent:-9999em;}

#msg{ width:340px; color: #333;font-size:14px; font-family:微软雅黑; color:#3b1807; margin-top:10px;}
#msg h3{ font-size:14px; font-weight:normal; color:#aa7140;}
.hot{ font-size:14px;color:#65412d;}
#error{ color:#333; font-size:14px; color:#C00;}
</style>
</head>

<body id=vip>
<div class="iframediv">
    	<div class="search">
    	  <input id="barCode" name="barCode" type="text" />
    	  <input type="button" id="btnSubmit" value="查询" />
    		<div id="msg"></div>
            <div id="error"></div>
        </div>
    </div></body>
</html>


提示错误:


但是:http://www.028search.com/ailend/search.html 这里测试输入“1” 显示正常的



请问一下 我这段AJAX 应该如何写?
  • 大小: 15.2 KB
  • 大小: 8.5 KB
   发表时间:2012-12-26  
你这个静态页面时用什么地址访问的?你要保证你这个静态页面的访问地址是:http://118.122.89.217:8808/ANBOSS 开头的。也就是跨域问题
0 请登录后投票
   发表时间:2012-12-26  
这是基本的跨域问题,ie和 firefox chrome等标准浏览器都有不同的权限标准。建议用jsonp来做。 不是问题。
0 请登录后投票
   发表时间:2012-12-26  
$.getJSON解决跨域
0 请登录后投票
   发表时间:2012-12-28  
jsonp只支持get方式,你要么用$.getJson,要么把type改成GET
0 请登录后投票
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics