Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught SyntaxError: Unexpected token < in <!DOCTYPE html>

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.com.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.com.kw/search-result.aspx?text=apple&searchfor=all',
        dataType: 'jsonp',
        success: function (data) {          
        console.log(data);
//$("#data").html(data);
        }
        }); 
    });
});
</script>
like image 474
Muhammad Saqlain Arif Avatar asked Feb 19 '15 07:02

Muhammad Saqlain Arif


People also ask

What does uncaught SyntaxError invalid or unexpected token mean?

The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided. This might be a simple typo.

What is unexpected token in Python?

Unexpected Token Perhaps you forgot the ':' after a conditional branch or there is an unclosed parenthesis left somewhere in your code? Python scripts are broken down into 'tokens' which helps the program navigate the logic of your code.


1 Answers

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.

like image 177
Samuel Goodell Avatar answered Sep 23 '22 00:09

Samuel Goodell