admin管理员组

文章数量:1391943

I tired using the proxy solution in

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

and on the file proxy.php I have

<?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);

In main I have

<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<script src="proxy.php"></script>
<link rel="stylesheet" href=".3.2/jquery.mobile-                1.3.2.min.css" />
<script src=".9.1.min.js"></script>
<script src=".3.2/jquery.mobile-1.3.2.min.js"></script>
<script type="text/javascript"     src=".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>Uping Movies</h1> 
</div> 
<ul id= "data" data-role="listview">
<li><img src=".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>

Now I call main.html in my localhost in Google chrome and the console says error on first line of php. I'm not sure what the problem is. The error message is: Uncaught SyntaxError: Unexpected token <

I tired using the proxy solution in

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

and on the file proxy.php I have

<?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);

In main I have

<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<script src="proxy.php"></script>
<link rel="stylesheet" href="http://code.jquery./mobile/1.3.2/jquery.mobile-                1.3.2.min.css" />
<script src="http://code.jquery./jquery-1.9.1.min.js"></script>
<script src="http://code.jquery./mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
<script type="text/javascript"     src="https://ajax.googleapis./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>Uping Movies</h1> 
</div> 
<ul id= "data" data-role="listview">
<li><img src="http://content8.flixster./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>

Now I call main.html in my localhost in Google chrome and the console says error on first line of php. I'm not sure what the problem is. The error message is: Uncaught SyntaxError: Unexpected token <

Share Improve this question edited May 23, 2017 at 12:22 CommunityBot 11 silver badge asked Aug 31, 2013 at 4:45 tcui222tcui222 3492 gold badges3 silver badges10 bronze badges 9
  • Possible duplicate: stackoverflow./questions/13351478/… – Amal Commented Aug 31, 2013 at 4:51
  • I saw previous questions like this. I think mine is different because the error is at the first line of my php code. the<?php is a syntax error? Its almost like <?php is not being recognized... – tcui222 Commented Aug 31, 2013 at 4:56
  • I don't see that part in your code? – Amal Commented Aug 31, 2013 at 4:57
  • The first line in proxy.php which i pasted as the first code section in my questions. The first line is <?php I think the console is telling me it doesn't recognize the < portion of it – tcui222 Commented Aug 31, 2013 at 4:59
  • Include your proxy.php code as well. – Amal Commented Aug 31, 2013 at 5:01
 |  Show 4 more ments

1 Answer 1

Reset to default 2

Just remove this line from your html:

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

本文标签: javascriptUncaught SyntaxError Unexpected token lt for list 1 of php (ltphp)Stack Overflow