8
votes

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>
2
Your url does not return any json with padding == JSONP - Jai

2 Answers

2
votes

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.

0
votes

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.com.kw/search-result.aspx',
        dataType: 'jsonp',
        data:{
            text: apple,
            searchfor: all
        }
        success: function (data) {          
        console.log(data);
        }
        }); 
    });
});
</script>

Hope this helps :)