0

That is the simple code from my index.html

http://pastebin.com/d2f7UuAa

In the script part I have:

<script type="text/javascript">
    $(document).ready(function() {  

            $('document').ready(function(){
                    $("#cv").click(function(){
                            $("#div1").load("cv.html",aviso());
                    });
            });

            function aviso(){
                    alert('La solicitud ha sido procesada');
            }
    });

</script>

And this is in cv.html

<h1>&iexcl;Mi CV!</h1>

I'm trying to use jQuery Ajax capability to display different content loading in an asynchronic way. I've already searched here and tried this: Dynamically load PHP within a main page but I've got no success. The function aviso() does execute although, but the content is not displayed. I know this is probably a very simple problem, but I'm stucked there. Thanks in advance!

8
  • try with this: load("cv.html", function() { aviso(); } Commented Feb 12, 2013 at 16:55
  • The file cv.html does exist, in the same dir as index.html Commented Feb 12, 2013 at 17:01
  • load("cv.html", function() { aviso(); } didn't make it either. Commented Feb 12, 2013 at 17:02
  • On the page, press F12, go to the console and type $("#div1").load("cv.html"). What happens? Commented Feb 12, 2013 at 17:08
  • XMLHttpRequest cannot load file:///C:/Users/Public/Documents/zaratemarcelo/cv.html. Origin null is not allowed by Access-Control-Allow-Origin. Commented Feb 12, 2013 at 17:11

2 Answers 2

0

The second $('document').ready is unnecessary and incorrect (should be without quotes).

Try this:

<script type="text/javascript">
    $(document).ready(function() {  

        $("#curriculum").click(function(){
            $("#div1").load("cv.html", aviso);
        });

        function aviso(responseText){
            alert('La solicitud ha sido procesada');
        }
    });
</script>
Sign up to request clarification or add additional context in comments.

4 Comments

@Marcelo Zárate - As Anthony Grist mentioned there's no element with an id of cv present in your HTML. I've updated the answer and changed the #cv to #curriculum
Actually, $(document) and $("document") are the same thing. I only found that out recently myself :)
I know the second document is unnecesary, it is commented. That was one solution someone give me and didn't work, of course.
@Archer - You're right, just tested that and it works. Didn't know that. Thanks for letting me know.
0

There's no element with an id of cv present in your HTML that I can see. Did you instead mean this link?

<li><a href="#" id="curriculum">Curr&iacute;culum Vitae</a></li>

If so, your jQuery code should be:

$("#curriculum").click(function(){
    $("#div1").load("cv.html", aviso);
});

Or you could change the value of the id attribute on the <a> element.

1 Comment

Yeah, that's because I thought of some kind of conflict with the id name, I tried last minute. But didn't worked before, when the names matched. Still doesn't.

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.