Reputation: 2923
Here is my code:
<script type="text/javascript">
$(".link").click(function(){
var id = this.id;
if(id == 'b1'){
$( "#conteudo" ).load( "teste.html", function(){
alert('Carregou de boa !');
});
}
});
</script>
All my pages are in localhost, I'm doing this just for study.
And this is the error that Chrome is giving me when I press the B1 button:
UPDATE Full Error:
OPTIONS file:///E:/mypath/folder/page.html No 'Access-Control-Allow-Origin'
header is present on the requested resource. Origin 'null' is therefore not allowed access.
Upvotes: 0
Views: 864
Reputation: 8912
If you're doing this locally, make sure you are visiting your page over http
and not the file
protocol.
Also, just to make sure you're going to same origin, you can add //
to the link like so:
$( "#conteudo" ).load( "//teste.html", function(){
You can pick up a local virtual machine webserver (Virtual Box) here: http://virtualboxes.org/images/
Upvotes: 1
Reputation: 2404
If you have python installed run SimpleHTTPServer with:
python -m SimpleHTTPServer
If you do this in the same dir where your web files are located you will have a webserver running in a very easy way
Upvotes: 0
Reputation: 943097
Chrome only does XMLHttpRequest
s over http(s). Use http://localhost
instead of file://localhost
Upvotes: 0