0

I have an issue with AJAX.

I am using Safari version 12.1.

This is my code:

<!DOCTYPE html>

<html lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="">
        <meta name="author" content="">
        <meta rel="icon" href="assets/images/favicon.ico">
        <title>Test</title>

        <!-- Custom CSS -->
        <link rel="stylesheet" href="assets/css/style.css">

        <!-- GoogleFonts -->

        <!-- HTML5 shiv and Respond.js IE8 support of HTML5 elements and media queries -->
        <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->

    </head>

    <body>
        <div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>

        <button>Get External Content</button>


        <!-- Imported JavaScript libraries -->
        <script src="assets/js/jquery-3.6.0.js"></script>
        <script src="assets/js/jquery.fullpage.js"></script>

        <!-- test Javascript files -->
        <!--<script src="assets/js/test.js"></script>-->

        <script>
            $("button").click(function(){
              $("#div1").load("ajaxload.html", function(responseTxt, statusTxt, xhr){
                if(statusTxt == "success")
                  alert("External content loaded successfully!");
                if(statusTxt == "error")
                  alert("Error: " + xhr.status + ": " + xhr.statusText);
              });
            });
        </script>

    </body>

</html>

This is the code for the ajaxload.html page

<h1>Portfolio</h1>

<p>Congratulations you have loaded content from an external page</p>

For some reason I keep on getting the error message.

halfer
  • 19,824
  • 17
  • 99
  • 186
ziggelflex
  • 23
  • 4
  • please post the error msg as well – Harshit Jan 14 '22 at 15:39
  • Error message. Error: 0: error – ziggelflex Jan 14 '22 at 15:41
  • 1
    Are you running this on a web server or your local computer? The code presented doesn't seem to have any obvious issues, but if you try to run it from your computer AJAX will not work. – EssXTee Jan 14 '22 at 16:04
  • I am running it locally. Is there a way I can get it to work locally? – ziggelflex Jan 14 '22 at 16:07
  • It can possibly be done, but this is essentially something browsers do not allow (for security purposes). See [this question](https://stackoverflow.com/questions/16683600/couldnt-ajax-local-file-from-local-html-page) for a better explanation. – EssXTee Jan 14 '22 at 16:10

0 Answers0