How Display data from url(cross-domain) on div usi

2019-09-10 17:59发布

问题:

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: *");
    ?>