문제

I'm simply trying to display the contents of a file retrieved by "$.get" but I'm not getting any results from the alert in the get . . Actually, the alarm in the get isn't even going off.

What am I doing wrong?

    $.ajax({ url:"tex.txt", complete:function(r){

        alert([
            'Response Status code: ' + r.status,
            "Response Text length: " + r.responseText.length,
            "Normal status code is 200",
            "Check console for more info and full response body"
        ].join("\r\n"));

        console.log(r.responseText, r);

    } }); 




Extra Info:

UPDATE: Console log showed three problems:

  • [blocked] The page at 'https://c9.io/lemony_andrew/projectgray/workspace/index.html' was loaded over HTTPS, but ran insecure content from 'http://code.jquery.com/jquery-latest.min.js': this content should also be loaded over HTTPS.

  • Uncaught ReferenceError: $ is not defined main.js:4

  • Uncaught ReferenceError: loaded is not defined index.html:13
  • 도움이 되었습니까?

    해결책 2

    The answer was more in depth than I could have thought.

    For some reason I could not connect to the Jquery library by using an external link like so:

    http://code.jquery.com/jquery-latest.min.js

    I had to copy the code and paste it into a file on my server.

    That solved the issue of jquery not being initialized. The next step was something I didn't even consider.

    When working with javascript:

    $.ajax({ url:"text.txt", complete:function(r){
    

    I would have imagined that that line of code would load the file correctly. But in fact, I didn't know that when you are referencing a file in javascript text.txt that you have to include the path from the page calling the javascript. I have the actual text file located in: javascript/text.txt because I thought the javascript loads files from the directory it's stored in...

    Thanks all that helped!

    다른 팁

    It's not certain whether the request actually happens.

    You need to fire up the page in Chrome Inspector's Network tab and check the XHR sub-tab.

    Alternatively, you can also try:

    $.ajax({ url:"tex.txt", complete:function(r){
    
        alert([
            'Response Status code: ' + r.status,
            "Response Text length: " + r.responseText.length,
            "Normal status code is 200",
            "Check console for more info and full response body"
        ].join("\r\n"));
    
        console.log(r.responseText, r);
    
    } }); 
    
    라이센스 : CC-BY-SA ~와 함께 속성
    제휴하지 않습니다 StackOverflow
    scroll top