0

I am learning jQuery on codeschool. All the way through the ajax lessons i could not get it to work. Please can somebody give me a push in the right direction. Thanks in advance.

Here is a jsfiddle..

https://jsfiddle.net/w202usyk/

and here is my code..

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset=utf-8 />
  <title>Where's Aggie???</title>

  <script type="text/javascript"    src='https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script>
  <link type="text/css" href="main2.css" rel="stylesheet">

 </head>

<body>

    <button class="btn"> Click Here</button>
    <div class='headbox'>
      <p class='main-title'>A</p>
    </div>

</div>
<script type="text/javascript" src="application2.js"></script>
</body>
</html>

My js..

$(document).ready(function() {
  $('button').on('click', '.btn', function(){
    $.ajax('http://www.jamesleetaylor.com/wheresaggie/b.html', {
          success: function(response) {
        $('.main-title').replaceWith(response);
      }
    });
  });
});

and CSS

.btn {
    margin-bottom: 20px;
}
.main-title {
    text-align: center;
}

.headbox {
    width: 100px;
    border: 3px solid black;
}
2
  • Is this call being made from a page opened on same domain and with www in address? Commented Feb 4, 2017 at 19:07
  • fixed it using a relative link. thank you Commented Feb 5, 2017 at 7:11

1 Answer 1

1

The problem is that you are getting the error: [Error] XMLHttpRequest cannot load http://www.jamesleetaylor.com/wheresaggie/b.html. Origin null is not allowed by Access-Control-Allow-Origin. because you need to allow access to your website.

Sign up to request clarification or add additional context in comments.

1 Comment

can you explain how to allow access?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.