2013-08-31 72 views
1

我累使用代理溶液中未捕获的SyntaxError:意外令牌<为PHP的列表1(?<PHP)

Origin http://localhost is not allowed by Access-Control-Allow-Origin.?

和在文件上proxy.php我有

<?php 
// File Name: proxy.php 
if (!isset($_GET['url'])) die(); 
$url = urldecode($_GET['url']); 
$url = 'http://' . str_replace('http://', '', $url); // Avoid accessing the file system 
echo file_get_contents($url); 

在主我

<!DOCTYPE html> 
<html> 
<head> 
<title>Title</title> 
<script src="proxy.php"></script> 
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-    1.3.2.min.css" /> 
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> 
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script> 
<script type="text/javascript"  src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> 
<script> 
$.ajax({ 
url:"proxy.php?url=theurlofmyapi", 
type:'GET', 
dataType:"json", 
success:function(data){console.log(data.results.result[1].category);} 
});</script> 
</head> 

<body> 
<div data-role="header"> 
<h1>Upcoming Movies</h1> 
</div> 
<ul id= "data" data-role="listview"> 
<li><img src="http://content8.flixster.com/movie/11/17/20/11172082_mob.jpg"   class="ui-li-thumb"><h3 class="ui-li-heading">Warning</h3><p class="ui-li-desc">hot</p>       </li> 
<li><a href="javascript:alert('hi')">Audi</a></li> 
<li><a href="bmw.html">BMW</a></li> 
</ul></body></html> 

现在我叫main.html中,我在谷歌ç本地主机hrome和控制台在php的第一行说错误。我不确定问题是什么。该错误信息是: 未捕获的SyntaxError:意外的标记<

+0

可能重复:http://stackoverflow.com/questions/13351478/json-parse-uncaught -syntaxerror-unexpected-token-t –

+0

我看到过像这样的问题。我认为我是不同的,因为错误是在我的PHP代码的第一行。 <?php是一个语法错误?它几乎像<?php不被识别... – tcui222

+0

我没有看到你的代码中的那部分? –

回答

1

刚刚从你的HTML删除此行:

<script src="proxy.php"></script> 
+0

是啊这是正确的解决方案,该行复制我的代码在那里第二次。由于proxy.php没有结束标记,因此出现错误 – tcui222

相关问题