0

This program runs well with phonegap server, but unable to run with other server or from the source i.e (file:///C:/Users/samsung%20pc/Desktop/arts/www/index_1_2.html)

When I run this program it gives me error :

  1. Origin file: not found in Access-Control-Allow-Origin header.
  2. XMLHttpRequest: Network Error 0x80700013, Could not complete the operation due to error 80700013.

What is wrong in this program. Any suggestion will be fine. Here is my code:

$(document).ready(function(){
$.ajax({
    type: "GET",
    url: "http://api.wolframalpha.com/v1/spoken?i=meaning+of+google&appid=...",
    async: false,
    dataType: "text",
    success: function (data, textStatus, jqXHR) {document.write(data);},onerror:function(e){document.write(e);}});});
Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • 1
    Ajax calls doesn't work from file:// protocol! And refer here for [Access-Control-Allow-Origin](http://stackoverflow.com/q/10636611/1681154) – Saurabh Sharma Feb 23 '17 at 09:21
  • @SaurabhSharma check the code shared by OP – Sagar V Feb 23 '17 at 09:25
  • You can send a GET or POST request if you use HTTP. But it doesn't make sense if you read a file from your hard disc. That's why AJAX doesn't work under `file://`. – Álvaro González Feb 23 '17 at 09:26
  • 1
    @RajatJaiswal Is there any relation between the Title and Your question? – Sagar V Feb 23 '17 at 09:26
  • Looks like you just need to allow cross-origin xhr requests. use open -a Google\ Chrome --args --disable-web-security --user-data-dir and let me know if it helps – DL Narasimhan Feb 23 '17 at 09:34

0 Answers0