Downloading the jquery file. AJAX upload files to server using jQuery. Connecting the jquery min js library


The first question that arises when starting to work with the jQuery library is how to connect it to the site? There are two options: connect from another site or download it to your server.

Connecting JQuery to the site1. The first and easiest is to use a file from another site. To do this, just one line before the closing head tag of your page is enough:


This code indicates connecting the library to the Google API. U this method there are both advantages and disadvantages. The advantage will be that this type connection is used on many sites and, for example, if the user has already visited a similar site, then he has the library cached and does not require new download. The downside is that you depend on a third-party server - its possible problems with downloading they become yours.

2. You upload your library file to the server

The latest version of jQuery can be downloaded from home page Official website: jquery.com.

Download the file. In the root directory (folder) of the server, create a js folder (if it does not exist) and upload the file there. Let's say the file is called jquery-1.10.1.js. Connection example below:


The line with the connection to the jQuery file should be the first in the list of included js files (if you have other js connections).





I also want to draw your attention to the fact that the connection to jQuery must be on all pages where it is used. There is not enough connection on one of the pages.

As already mentioned, many popular CMSs today already come with jQuery, and WordPress is no exception. However, if the library is not included with plugins, then jQuery will not be loaded automatically. To connect this framework correctly, you need to use the wp_enqueue_script() function. Place the following code in your theme's header.php file (open through an editor):

How to include the jQuery library in WordPress? Nowadays, almost all CMS use built-in jQuery. It remains to be connected with a special command. Plugins do not always include the library automatically, so some blocks and modules may not work. To connect, you should use the wp_enqueue_script() function.

Below is the code that needs to be written in the header.php file (open through an editor)

Wp_enqueue_script("jquery");
This function must be placed between the head tags BEFORE calling the wp_head() function. This order will save time loading the page.

How to include the jQuery library in Joomla? Code to be inserted into the handler

$document = JFactory::getDocument();
$document->addScript("http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"); // here it doesn’t matter where the connection is from, it can be from the network.
/* or else */
$document->addScript("http://mysite/js/.js");
In the case of a template version of the page, you need to insert PHP code


Top