How Display data from url(cross-domain) on div using dreamweaver phonegap?

拈花ヽ惹草 提交于 2020-01-17 06:06:15

问题


What is the best way to display some content of a url (#somediv) on a div of my HTML Dreamweaver Phonegap

I am new on Phonegap DW and i want to display the weather values of this page:

http://www.catedralaltapatagonia.com/invierno/partediario.php?default_tab=0

In Java U used Jsoup, but i am not sure how do it on DW

I tried this code (AJAX and JSONP)

HTML

<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>

<script src="js/jquery-1.5.min.js"></script>
<script src="js/load-json.js"></script>
</head>
<body>
<div id="output"></div>
</body>
</html>

JS

 $(document).ready(function(){
var output = $('#output');

$.ajax({
    url: 'http://www.catedralaltapatagonia.com/invierno/partediario.php? default_tab=0',
    dataType: 'jsonp',
    jsonp: 'jsoncallback',
    timeout: 5000,
    success: function(data, status){
        $.each(data, function(i,item){ 
            var landmark = '<h1>'+item.name+'</h1>'
            ;

            output.append(landmark);
        });
    },
    error: function(){
        output.text('There was an error loading the data.')
    }
});
});

回答1:


i think you have to enabled CORS for this, you can enable cors via:

.htaccess
    Header set Access-Control-Allow-Origin "*"

or via

.php (together with the codes)
    <?php
        header("Access-Control-Allow-Origin: *");
    ?>


来源:https://stackoverflow.com/questions/34429039/how-display-data-from-urlcross-domain-on-div-using-dreamweaver-phonegap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!