Javascript 使用dreamweaver(跨域请求)时,AJAX和YQL不起作用

Javascript 使用dreamweaver(跨域请求)时,AJAX和YQL不起作用,javascript,jquery,html,ajax,cordova,Javascript,Jquery,Html,Ajax,Cordova,我使用js在我的应用程序上显示一些内容,我使用Dreamweaver和PhoneGap。当我单独预览html时,效果很好,但当我从其他页面加载html时,效果就不好了 我在Firefox Security:ReferenceError:requestCrossDomain上收到此消息未定义 这是我的HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>jQuer

我使用js在我的应用程序上显示一些内容,我使用Dreamweaver和PhoneGap。当我单独预览html时,效果很好,但当我从其他页面加载html时,效果就不好了

我在Firefox Security:ReferenceError:requestCrossDomain上收到此消息未定义

这是我的HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery Mobile Web App</title>
<script src="js/jquery-1.11.0.min.js"></script>
<script src="js/cross-domain-request.js"></script>


</head>
 <body>

<div id="container">

<p id="sitename"> http://catedralaltapatagonia.com/invierno/partediario.php? default_tab=0
</p>

和我的cross-domain-request.js:

/ JavaScript Document
// Accepts a url and a callback function to run.
function requestCrossDomain( site, callback ) {



 // Take the provided url, and add it to a YQL query. Make sure you encode it!
 var yql = 'http://query.yahooapis.com/v1/public/yql?q=' +  encodeURIComponent('select * from html where url="' +  'http://catedralaltapatagonia.com/invierno/partediario.php?default_tab=0' +  '"'+' AND xpath="//*[@id=\'meteo_recuadro\']"') + '&format=xml&callback=?';






// Request that YSQL string, and run a callback function.
// Pass a defined function to prevent cache-busting.
$.getJSON( yql, function(data){

      // If we have something to work with...
if ( data.results[0] ) {
    // Strip out all script tags, for security reasons.
    // BE VERY CAREFUL. This helps, but we should do more. 
    data = data.results[0].replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');

    // If the user passed a callback, and it
    // is a function, call it, and send through the data var.
    if ( typeof callback === 'function') {
        callback(data);

    }
}
// Else, Maybe we requested a site that doesn't exist, and nothing returned.
else throw new Error('Nothing returned from getJSON.');
});
}


有什么线索可以解决吗?

您的外部JS文件中似乎有错误,并且它没有运行。最后的else语句不正确。试试这个:

 / JavaScript Document
// Accepts a url and a callback function to run.
function requestCrossDomain( site, callback ) {

 // Take the provided url, and add it to a YQL query. Make sure you encode it!
 var yql = 'http://query.yahooapis.com/v1/public/yql?q=' +  encodeURIComponent('select * from html where url="' +  'http://catedralaltapatagonia.com/invierno/partediario.php?default_tab=0' +  '"'+' AND xpath="//*[@id=\'meteo_recuadro\']"') + '&format=xml&callback=?';

// Request that YSQL string, and run a callback function.
// Pass a defined function to prevent cache-busting.
$.getJSON( yql, function(data){

      // If we have something to work with...
  if ( data.results[0] ) {
    // Strip out all script tags, for security reasons.
    // BE VERY CAREFUL. This helps, but we should do more. 
    data = data.results[0].replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');

    // If the user passed a callback, and it
    // is a function, call it, and send through the data var.
      if ( typeof callback === 'function') {
        callback(data);

      }
    }
    // Else, Maybe we requested a site that doesn't exist, and nothing returned.
    else {   
      throw new Error('Nothing returned from getJSON.');
    }
  });
}
我加一行

  <script src="js/cross-domain-request.js"></script>

而js被加载了

还是什么都没有。html名为metereolo.html。如果我预览了meterelo.html文件,但是从index.html调用了when…doesnt.你是否检查了控制台以确保两次都加载了外部文件?js是在我从预览开始加载时加载的,而不是在我从indexI加载页面时加载的,显然我不知道你的文件结构,但是如果没有加载JS文件,那么您就有问题了。控制台应显示网络错误,并给出浏览器试图获取JS文件的路径。也许可以尝试以下操作:。我决定添加到index.html。然后加载js
  <script src="js/cross-domain-request.js"></script>