- 1

.load function in Jquery isn't working. Can anybody tell me where i am going wrong?

<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("#div1").load("demo_test.txt"); }); }); </script> </head> <body> <div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div> <button>Get External Content</button> </body> </html>

5th Aug 2017, 10:47 AM
Atul Chandran
Atul Chandran - avatar
9 Réponses
+ 5
Your code work well if the file 'demo_test.txt' exist in the same folder than your source code file ^^ However, it could not work in code playground with other url than abssolute (complete urls), as relative location will be on sololearn servers, where you cannot upload any external ressources for your web projects in playground (or anywhere, but elsewhere you could have required right to do so)... This means also that for working in code playground, you need to upload any external ressources somewhere on internet ;P
5th Aug 2017, 11:08 AM
visph
visph - avatar
+ 4
It work well for me, with local files... Are you sure of the text file name? You wrote 'demo_test.txt' in your code and 'demo_txt' in your reply ;P
5th Aug 2017, 11:21 AM
visph
visph - avatar
+ 4
If your are on unix-like OS (linux, OSX...) and even on Window (but less probable), you need to verify the file rights (user, group, read access...)
5th Aug 2017, 11:31 AM
visph
visph - avatar
+ 3
No default: it's working ^^
5th Aug 2017, 11:25 AM
visph
visph - avatar
0
I haven't tried this code in Sololearn code playground... But the demo_txt file is present in the same directory
5th Aug 2017, 11:18 AM
Atul Chandran
Atul Chandran - avatar
0
The demo_test.txt doesn't open when I clicked the button... There is no error though
5th Aug 2017, 11:28 AM
Atul Chandran
Atul Chandran - avatar
- 1
I meant that actually :P...
5th Aug 2017, 11:22 AM
Atul Chandran
Atul Chandran - avatar
- 1
Can you please tell me if there is any flaw in the code please?
5th Aug 2017, 11:23 AM
Atul Chandran
Atul Chandran - avatar
- 1
Are there any plugins I need to include?
5th Aug 2017, 11:29 AM
Atul Chandran
Atul Chandran - avatar