0

Hi there I'm still quite new with jQuery. I have a html file which contains a span that I would like to fetch and populate from a file on server. Here is my HTML file:

<div class="home-page main">
<section class="grid-wrap" >
    <header class="grid col-full">
    <hr></hr>
        <p class="fleft">首頁</p>
    </header>

    <div class="grid col-one-half mq2-col-full">
        <span class="Welcome_Message"></span>
    </div>
    </section>
</div>

Then here is my jQuery script file:

$.get('texts/Welcome_Message.txt', function(data) {
    $('.grid span').html(data);
}).done(function() { alert("success"); })
  .fail(function() { alert("error"); });

I've tried with the preview in DreamWeaver and it will populate and show the alert("success"); message properly. However running it in a browser (no matter which one) shows the alert("error"); and the span is not populated. Anyone can help please?

1 Answers1

0

I think you simply need to load the data into the (.Welcome_Message) straight away. though i don't know why you need the response

<script>
$(document).ready(function () {
   $('span.Welcome_Message').load("texts/Welcome_Message.txt");
   });
</script> Also check this link  http://stackoverflow.com/questions/4208530/xmlhttprequest-origin-null-is-not-allowed-access-control-access-allow-for-file/
ShapCyber
  • 3,382
  • 2
  • 21
  • 27
  • thank you for answering, however in fact the function is **already** in the $(document).ready() event... –  Jun 06 '13 at 01:39
  • Okay then simply pop in that line $('span.Welcome_Message').load("texts/Welcome_Message.txt"); – ShapCyber Jun 06 '13 at 01:41
  • I've tried it buddy... yet it is still only showing in dreamweaver... not inside a browser –  Jun 06 '13 at 01:44
  • okay create new page add this to the top then in the body type this line open in a browser – ShapCyber Jun 06 '13 at 01:47
  • nothing had changed... still showing in dreamweaver but not in browser... thank you for actively trying to help me out btw =] –  Jun 06 '13 at 01:50
  • what type of browser are you using – ShapCyber Jun 06 '13 at 01:53
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/31292/discussion-between-matthew-and-shapcyber) –  Jun 06 '13 at 01:58
  • Try changing the extension from Welcome_Message.txt to Welcome_Message.html – JanR Jun 06 '13 at 02:27