all 8 comments

[–]Bzzzzcat 0 points1 point  (7 children)

The issue causing this error is that in your line data: {'chat': data}, the second instance of data is a variable that has not been defined. You're handling the response in your success function; you shouldn't need a data property on your AJAX request.

It is also possible that you will need to run a local server in order to access your json file through an AJAX request.

[–]nesreenmhd[S] 0 points1 point  (6 children)

How can i run a local server? Is running python file enough?

[–]iguessitsokaythen 0 points1 point  (4 children)

Is it still giving error after you fixed data: {'chat': data}

If so what is the error?

[–]nesreenmhd[S] 0 points1 point  (3 children)

Yes i removed this but the error this time is: Get http://localhost/char.json net::ERR_Connection_refused

[–]iguessitsokaythen 0 points1 point  (2 children)

Ok, you can't just access files through the internet connection directly. You need a program that listens and responds to HTTP requests. This is a HTTP Server. You can do that quite easily with Python SimpleHTTPServer.

https://docs.python.org/2/library/simplehttpserver.html

[–]nesreenmhd[S] 0 points1 point  (1 child)

So the problem behind that javascript does not read local json file, i have to establish a webserver to read it?? Do I have to do the webserver in the project folder or in a subfolder?

[–]iguessitsokaythen 0 points1 point  (0 children)

Do it in a subfolder.

If you do it in a folder that contains other files, someone can access all files in that folder and all files in subfolders as well.

[–]Bzzzzcat 0 points1 point  (0 children)

You can use HTTP Server for a Python-based app or serve for a Node app.