0

I am a newbie to jQuery and was trying to load content dynamically using AJAX and jQuery using the following code but its not working.

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$("button").click(function()
{
$(".text").load("http://api.jquery.com/get/");

});

});
</script>
<title>AJAX with jQuery</title>
</head>
<body>
<div class="text">Sushil</div>
<button>Load Text</button>
</body>
</html>
1

2 Answers 2

2

You are violating the same origin policy. Just open your console and see the error message when you click the button. Things will become clearer to you. If not please get back

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

4 Comments

I tried to load a local html file in the same directory bu using $(".text").load("txtfile.txt") but still no results. Can you give me an example how to load a file in div using AJAX?
your code is working perfectly for me if both files are in the same directory.. can you tell me what error you are getting... just open the console you will get to know the error
hmm tough call.. ok what browser are you using
0

I ran your code and I got this error: XMLHttpRequest cannot load http://api.jquery.com/get/. Origin null is not allowed by Access-Control-Allow-Origin.

I googled it and I got this: Origin null is not allowed by Access-Control-Allow-Origin

1 Comment

I used firebug, you can also use google chrome developer tools (Ctrl + Shift + I)

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.