天地图js跨域访问实现输入地名搜索定位地图上的点function getgeocode()
{
//关于跨域访问,请自行解决,目前示例是通过服务器端转发的方式解决
//关于服务参数的设置请自行参考网站 http://221.2.153.36:8719/newmapserver4/SDK/REST/index.html?service/capabilities.html
//下面仅以属性查询为例
var url = "http://221.2.153.36:8719/newmapserver4/rest/services/whjiazheng/dmdz/featureserver/query?layer=dmdz&page=1&maxitems=10&format=json&where=";

var querytext = document.getElementById('dmtxt').value;
var where = " NAME like '%"+querytext+"%'";
url += where;
url = encodeURI(url);
var proxyStr ="./proxy.php?url=";  
var fullRequestURL = proxyStr + encodeURIComponent(url);  
alert(fullRequestURL);
//alert(encodeURIComponent("http://127.0.0.1:8719/newmap/rest/services/samples/china/FeatureServer/query?layer=首都和省级行政中心&page=1&maxitems=10&format=json&where=NAME like '%济南%'"));
NRequest.GET({  
url: fullRequestURL,  
success: SCallBack,  
failure: FCallBack  
});  
//注意:上面仅仅提供了怎么组织url,服务器端的服务url中有中文,要求编码是utf-8
}

解决方案 »

  1.   

    如果对方提供回调接口的话jsonp试试
    或者通过后台实现简单一点  纯js好像不能的样子
      

  2.   

    告诉你吧,如果你是本地文件运行JS,可以跨域,如果是带地址的文件运行JS,是无法跨域的,除非服务器给你回调函数。
      

  3.   

    这个不行的,,除非设置ie,但是每个访问者都要设置,显然不行使用jquery也会报错 没有权限,,,,
    之前做个一个,最终使用iframe 做中间桥梁 实现的。
      

  4.   

    需要把内容做个中转,简单的说就是把内容下载下来,拿到内容在去做调用
    public String downloadFile(String fileId) {
    String downFile = "";
    StorageClient1 client = null;
    try {
    client = getDfsClient();
    // 从服务器端下载文件
    byte[] bFlie = client.download_file1(fileId); downFile = new String(bFlie, "UTF-8");
    } catch (Exception e) {
    connList.remove(client);
    destroy();
    }
    return downFile; }
           /**
     * 确保获取有效通信
     * 
     * @return
     */
    public StorageClient1 getDfsClient() {
    StorageClient1 client = null;
    if (connList.size() == 0)
    createDFSConn();
    while (client == null) {
    synchronized (connList) {
    client = connList.get(0);
    if (client == null)
    createDFSConn();
    }
    }
    return client;
    }
    这种方式java的方式,但是我想php,也是这个原理,具体的php代码,自己写
      

  5.   

    jquery.ajax 用请求格式用jsonp 可以跨域访问