来自url的jquery .get xml文件

时间:2022-12-24 09:43:48

So i have a simple task, get an xml feed from a server that is not ours. easy enough, however im running into allow origin control issues and the &callback= tag isnt solving the issue.

所以我有一个简单的任务,从不属于我们的服务器获取xml提要。很容易,但我遇到允许原始控制问题和&callback =标签不解决问题。

$.get("http://www.buytopia.ca/feed",data,jloop(),"xml");

function jloop(){
        var count=0;
        //dummy code
        document.write("please work");
        do{
            document.write(count);
            count++;
        }
        while (count<10);

    };

so when i run this, the get call is pending, not retieving. ive tried different feeds, like NASA but adding the &callback= doesnt remove access origin problems. All i need is a working chunk of code to get the feed, preferably to that buytopia.ca feed because we have access to it and know its permission info. Then i can begin to parse it. Any help would be great! thanks!

所以当我运行这个时,get调用正在等待,而不是在调整。香港专业教育学院尝试了不同的饲料,如美国国家航空航天局,但添加&callback =不会删除访问源问题。我只需要一个工作的代码块来获取feed,最好是那个buytopia.ca feed,因为我们可以访问它并知道它的权限信息。然后我可以开始解析它。任何帮助都会很棒!谢谢!

2 个解决方案

#1


0  

You can do an ajax call to a local php file (let's say you call it currency.php), and get it through php as in, for example (the php is from ECB's web site, for developers - the ajax is mine)

你可以对本地php文件进行ajax调用(假设你称之为currency.php),并通过php获取它,例如(php来自ECB的网站,对于开发人员 - ajax是我的)

  $XML=simplexml_load_file("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");

  //the file is updated daily between 2.15 p.m. and 3.00 p.m. CET 

    foreach($XML->Cube->Cube->Cube as $rate){
        //Output the value of 1EUR for a currency code
        echo '1&euro;='.$rate["rate"].' '.$rate["currency"].'<br/>';

        if ($rate["currency"]=='USD') {
            echo 'EUR-> USD RATE: '.$rate["rate"], '<br/>';
        }
        //--------------------------------------------------
        //Here you can add your code for inserting
        //$rate["rate"] and $rate["currency"] into your database
        //--------------------------------------------------
    }

Then the ajax call would be something like:

然后ajax调用将是这样的:

<script>
 $.ajax({
        url: 'currency.php',
        type: 'POST',
        data: {myCurrency: curr,
               myPriceAmt: amount },  
        success: function(data){
            // do any manipulations here

        }
 });
 </script> 

Good luck!

#2


0  

Is buytopia your domain. You cant make ajax calls accross domains. Its called cross site scripting.

buytopia是您的域名吗?你不能在域之间进行ajax调用。它被称为跨站点脚本。

https://en.wikipedia.org/wiki/Cross-site_scripting

#1


0  

You can do an ajax call to a local php file (let's say you call it currency.php), and get it through php as in, for example (the php is from ECB's web site, for developers - the ajax is mine)

你可以对本地php文件进行ajax调用(假设你称之为currency.php),并通过php获取它,例如(php来自ECB的网站,对于开发人员 - ajax是我的)

  $XML=simplexml_load_file("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");

  //the file is updated daily between 2.15 p.m. and 3.00 p.m. CET 

    foreach($XML->Cube->Cube->Cube as $rate){
        //Output the value of 1EUR for a currency code
        echo '1&euro;='.$rate["rate"].' '.$rate["currency"].'<br/>';

        if ($rate["currency"]=='USD') {
            echo 'EUR-> USD RATE: '.$rate["rate"], '<br/>';
        }
        //--------------------------------------------------
        //Here you can add your code for inserting
        //$rate["rate"] and $rate["currency"] into your database
        //--------------------------------------------------
    }

Then the ajax call would be something like:

然后ajax调用将是这样的:

<script>
 $.ajax({
        url: 'currency.php',
        type: 'POST',
        data: {myCurrency: curr,
               myPriceAmt: amount },  
        success: function(data){
            // do any manipulations here

        }
 });
 </script> 

Good luck!

#2


0  

Is buytopia your domain. You cant make ajax calls accross domains. Its called cross site scripting.

buytopia是您的域名吗?你不能在域之间进行ajax调用。它被称为跨站点脚本。

https://en.wikipedia.org/wiki/Cross-site_scripting