locked
Ajax page - Timer.cshtml - where do I look to solve this. RRS feed

  • Question

  • User483055775 posted

    I am re-running through the examples in my webmatrix books - and having a perplexing problem.   I have a page, called Timer.cshtml -which I copied from the example in the books download code - and when I run in from the example code, the time clock ticks second by second nicely - I copy that same page into my starter site app, as well as the jquery-1.6.2.min.js file into the /scripts folder and it doesnt work.  So the same page - linked to only that one .js file - works in the example folder - but not in my startersite folder.  I need Ajax in an app I am writing and I need this example to work  - what would be the most obvious mistake I could make to screw this up.  and the folder and the name of the .js file are perfect, I copied and pasted them to be sure.  Thanks in advance.

    DonnieS

    Sunday, September 21, 2014 12:26 AM

Answers

  • User-821857111 posted

    Gettime is not a function in the jQuery file in my book. I would never add anything to the jQuery file. GetTime is a Razor .cshtml file. All it contains is one line of code:

    @DateTime.Now

    This file goes into the root of your site.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, September 21, 2014 5:16 PM

All replies

  • User895691971 posted

    Since that code works than there is an error with your own StarterSite project. I believe there is some other JavaScript code or library required for it. 

    Would you mind sharing minimum code to work on, the buggy code you're having etc? 

    The one thing that you can do to understand the trouble would be to open the Developer Tools in your browser, press F12 and go to the Console, Console would let you know what is missing that was required. It would give you the errors that are causing troubles in your project. You can yourself manage this project by using the Console errors and Googling them, or try to provide a fiddle for that. 

    Sunday, September 21, 2014 3:37 AM
  • User483055775 posted

    Thank you so much Ahmad,  I had forgotten about using F12 - it tells me that it cant find GetTime in the StarterSite project - but it can in the identical timer.cshtml over in the example code - this is from Mike's book btw.  I have this to reference the .js file - 

     <script src="~/Scripts/jquery-1.8.2.min.js"></script>

    The line below is the line from the example code - I have tried it , but it doesnt work in the StarterSite Project - the example code is Chapter6 of Mike's book, which like I said , works fine.  So i am using F12 to chase this down - though havent got it yet.

     <script src="@Href("~/Scripts/jquery-1.8.2.min.js")" type="text/javascript"></script>

    Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:17711/GetTime/?_=1411301258005
    Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:17711/GetTime/?_=1411301259006
    GET http://localhost:17711/GetTime/?_=1411301260007 404 (Not Found) jquery-1.8.2.min.js:2
    GET http://localhost:17711/GetTime/?_=1411301261007 404 (Not Found)

    Sunday, September 21, 2014 8:13 AM
  • User895691971 posted

    The error messages tell you that the files are not file. GetTime file at the root location, isn't found. I really believe you're missing the reference, or the file itself. I believe there would be some Read this kind of thing on the page if this is the exact copy of that code. 

    However you can make sure that all the files are present at the same location they must be. Specially that GetTime file and the JavaScript resources.

    Sunday, September 21, 2014 8:37 AM
  • User483055775 posted

    getTime is in the -> 

     <script src="@Href("~/Scripts/jquery-1.8.2.min.js")" type="text/javascript"></script>

    and this file is in the Scripts folder.

    Sunday, September 21, 2014 10:00 AM
  • User895691971 posted

    Well in that case, you can click on the line that represents the error on the right side where you're seeing the error in the Console. It will take you to the line in the file where the error is with a little information too. 

    Secondly, why don't you download a new version of the file. It might have been damaged.

    Sunday, September 21, 2014 12:08 PM
  • User483055775 posted

    The download is new - I have used an old one too - and I switch to the cdn of the jquery file just to make sure.

    Sunday, September 21, 2014 2:20 PM
  • User-821857111 posted

    getTime is in the -> 

     <script src="@Href("~/Scripts/jquery-1.8.2.min.js")" type="text/javascript"></script>

    and this file is in the Scripts folder.

    I don't understand. Are you saying that gettime is in the scripts folder? If so, move it to the root folder of the site.

    Sunday, September 21, 2014 4:09 PM
  • User483055775 posted

    GetTime is in jquery-1.8.2.min.js,  its a function in that javascript file - checked capitalization, everything.  What I cant understand is why it works in the Chapter6 folder from your book - but when I copy that page into an empty, or startersite or my working app - it does not work.  I moved the particular .js file - its in the /Scripts folder of course, like the example said to do - but I moved the jquery-1.8.2.min.js file from the site I am working on - over to the chapter6 folder - and it still works there - just not in anything I touched.  Starting to think i have an hex on me (lol).    

    DonnieS

    Sunday, September 21, 2014 5:07 PM
  • User-821857111 posted

    Gettime is not a function in the jQuery file in my book. I would never add anything to the jQuery file. GetTime is a Razor .cshtml file. All it contains is one line of code:

    @DateTime.Now

    This file goes into the root of your site.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, September 21, 2014 5:16 PM
  • User483055775 posted

    Holy jeez - I am so sorry for bothering you and Ahmad.  I see the file - I thought it was a function inside the jquery file.

    Thank you guys - thank you.

    DonnieS

    Sunday, September 21, 2014 5:21 PM