最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Uncaught SyntaxError: Unexpected token < in <!DOCTYPE html> - Stack Overflow

programmeradmin8浏览0评论

i am sending a ajax request to external domain. Here is my code, There might be an issue on JSONP response while converting the html data to jsonp. I have tried so many solution because i am requesting to cross domain so i have to use JSONP else i have to face cross domain error. Error when Use simple JSON ERROR: " XMLHttpRequest cannot load .aspx?text=apple&searchfor=all. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'localhost:49324' is therefore not allowed access."

Response error: Uncaught SyntaxError: Unexpected token <

<script type="text/javascript">
  $(document).ready(function(){
      $("#bt").click(function(){
       $.ajax({
        type: 'GET',
        url: '.aspx?text=apple&searchfor=all',
        dataType: 'jsonp',
        success: function (data) {          
        console.log(data);
//$("#data").html(data);
        }
        }); 
    });
});
</script>

i am sending a ajax request to external domain. Here is my code, There might be an issue on JSONP response while converting the html data to jsonp. I have tried so many solution because i am requesting to cross domain so i have to use JSONP else i have to face cross domain error. Error when Use simple JSON ERROR: " XMLHttpRequest cannot load http://www.blink..kw/search-result.aspx?text=apple&searchfor=all. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'localhost:49324' is therefore not allowed access."

Response error: Uncaught SyntaxError: Unexpected token <

<script type="text/javascript">
  $(document).ready(function(){
      $("#bt").click(function(){
       $.ajax({
        type: 'GET',
        url: 'http://www.blink..kw/search-result.aspx?text=apple&searchfor=all',
        dataType: 'jsonp',
        success: function (data) {          
        console.log(data);
//$("#data").html(data);
        }
        }); 
    });
});
</script>
Share Improve this question edited Feb 19, 2015 at 8:09 Muhammad Saqlain Arif asked Feb 19, 2015 at 7:40 Muhammad Saqlain ArifMuhammad Saqlain Arif 5441 gold badge5 silver badges16 bronze badges 1
  • 1 Your url does not return any json with padding == JSONP – Jai Commented Feb 19, 2015 at 7:46
Add a ment  | 

2 Answers 2

Reset to default 2

This is probably happening because you are specifying it as JSONP, which executes the data as a script in order to execute a callback function. If it sends back a normal HTML document with the doctype being the first line it sees, this would occur.

Try this code, basically we should not use url like this. Also, this url is not return any json or jsonp format, please check your link as well

<script type="text/javascript">
  $(document).ready(function(){
      $("#bt").click(function(){
       $.ajax({
        type: 'GET',
        url: 'http://www.blink..kw/search-result.aspx',
        dataType: 'jsonp',
        data:{
            text: apple,
            searchfor: all
        }
        success: function (data) {          
        console.log(data);
        }
        }); 
    });
});
</script>

Hope this helps :)

发布评论

评论列表(0)

  1. 暂无评论