[Solved] Ajax Jquery doubts [closed]


jQuery code will not work without the library being referenced on your page (usually in the <head> tags).

Also, there are some other libraries that build on top of the jQuery library, like Twitter’s excellent bootstrap library, or jQueryUI. In those cases, you need both the jQuery library and the additional library — as shown for jQueryUI in the first example below.

There are a few options for including jQuery libraries on your page.

CDNs (Content Delivery Networks) are online storage locations where web pages can grab the specified code, without you needing to store it on your server. This is why a CDN is a good idea.

One: 1. Use a CDN:

<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
</head>

Two: 2. Download the jQuery script:

  • Go here: http://jquery.com/download/
  • Click on the version you want
  • When you see the code in your browser, save that into a text file
  • It is simplest to just store the jquery.js file in your webroot (usually public_html), but you can store it anywhere (and name it anything you want — you just have to use the same name/location when you reference it in your <script> tag.
  • Below example has it stored in a subdir called js
  • Include it in your head tags, thus:

Three: 3. A combination of the above, with fallback

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script> window.jQuery || document.write('<script src="../js/jquery-1.10.2.min.js"><\/script>')</script>

The above code does this:

a. Load the jQuery library from the CDN
b. IF the CDN did not load, then load the jQuery from the specified location on my server (Note that the jQuery library must also be available on your server, at the location specified).

Notes:

  • There are two forms of the jquery.js code that you can use: minified and regular. The difference is that the minified code loads faster, but the regular code code is human-readable. Use whichever one you wish. If you decide to customize the jQuery library for your own purposes some day, you will want to edit the human-readable one.

solved Ajax Jquery doubts [closed]