I am new to Jquery and AJAX. I am trying to upload the file using AJAX call. When I set the script reference as from website, its working fine, but when I download it and set reference as local folder, its not working. What is wrong with my code?
When I use :
<script src="http://malsup.github.com/jquery.form.js"></script>
its working fine,
but when I use
<script type="text/javascript" src="http://localhost:8080/Upload/js/jquery.js"></script>
or
<script type="text/javascript" src="js/jquery.js">
its not working......
Add jquery.form.js library in your website folder under js folder, and
Change
<script type="text/javascript" src="js/jquery.js">
To
<script type="text/javascript" src="js/jquery.form.js">
This version points to a file on that web site:
<script src="http://malsup.github.com/jquery.form.js"></script>
This version points to a file on your LOCAL server (machine) via port 8080 (usually NOT a great idea)
<script type="text/javascript" src="http://localhost:8080/Upload/js/jquery.js"></script>
This verison points to a js folder relative to the page it is linked on
<script type="text/javascript" src="js/jquery.js">
In order to use a file locally (like the last two), you will need to download that file, and save it to your web server (or local server) in a folder. In the second example, this would mean saving it to the Upload\js folder at the root of your local servers site (that machine).
In the third example, you would need to find the page it is linked in, create (if not present) a js folder under that folder and save the js file at that location.
Note that it is always a good idea to use the original name form or something similar rather than jQuery.js - as that is often confused with the jQuery library itself.
An examples might be save it as:
jquery.form.js
malsup.jquery.form.js
malsup.version1.jquery.form.js
or some such named instance.
NOTE One way of making this as generic as might be would be to use
<script type="text/javascript" src="/Upload/js/jquery.js"></script>
This points to a folder called Upload with a sub folder js (Upload\js)which is based at the root of your web site. For instance if your site is based at your windows e: drive in a wwwroot folder it might be:
E:\wwwroot\Upload\js\malsup.jquery.form.js
Related
I have simple one page html/js/ReactJS app which is used with the help of such scripts added to index.html. It is running without any server, because client needs it to be used only on his computer:
<script crossorigin src="https://unpkg.com/react#16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom#16/umd/react-dom.production.min.js"</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.25.0/babel.min.js"></script>
How can I make this app working offline? I can use Node Server, but when application is downloaded by client it needs to be opened using the only index.html file.
Just download the three files above:
react : https://unpkg.com/react#16/umd/react.production.min.js
react-dom : https://unpkg.com/react-dom#16/umd/react-dom.production.min.js
babel : https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.25.0/babel.min.js
You can do this by going to the src links in your script tags above, right-click the webpage, click Save As, choose file type as JavaScript and then replace the above src links in your index.html to those downloaded files.
You can create a special folder for the site and within the folder, you can paste a copy of your index.html file as well as a js folder and keep the above three downloaded JavaScript files in that js folder.
You can now simply replace the src link in the above three scripts tags like this:
<script src="js/react.production.min.js" />
<script src="js/react-dom.production.min.js" />
<script src="js/babel.min.js" />
However, this only works if the client is just viewing the site. If the client wants to say, edit the files and want something like hot reload, they will need to set up a server for that.
I have just wrote a javascript file which I ran the via intelliJ using a few different browsers e.g. Google Chrome. This works fine as it runs locally e.g. http://localhost://.
However I want to be able to send it to someone so they just click on the .html file (packaged in correct folder) and it appears on their browser. Is there anyway I can do this? Right now the url points locally e.g. file:///Users/**/project/file.html.
Use a relative path. If your HTML file is in the same folder as the JS file, this means simply including it like so:
<script src="jsfile.js"></script>
If it's in a subdirectory, include all the folders necessary to get there:
<script src="subdirectory1/subdirectory2/jsfile.js"></script>
If it's up a directory, use the .. path:
<script src="../anotherfolder/jsfile.js"></script>
Or just include it in the HTML page itself:
<script>
// your code here
</script>
When I use the following header
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
There is no error in my HTML file. But I am facing a problem. Every time I am loading this page , there is the need for internet connectivity.
I have developed an webpage through which some instruments would be controlled through node.js acting as a server. This would be accesible in the intranet (between local computers in LAN) only.
Is there any method to use jquery as a local resource, i.e. If i download and save these files and use it from the local hard disk.
I saved both the files jquery-1.8.3.js and jquery-ui.js in the same folder as the html and used it with <script src="/jquery-ui.js"></script> it is giving resource not found 404 error.
If the .js file is in the same folder as the .html, then you should be able to include it with
<script src="jquery-1.8.3.js"></script>
Download the jquery and put it in your scripts folder and use like this
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="scripts/jquery-1.8.3.min.js"><\/script>')</script>
This will first check for the CDN if exist it will load from CDN other wise it will take local one
uses of CDN are in this link
I run a sub-site at my work, and while my live site is on the same "main server" as the company's main site, my dev environment is hosted on a separate server.
For some reason my dev site is unable to access a specific JavaScript file that is hosted on the "main server". All of the other JavaScript files, like jQuery, and jQueryTools can be accessed, but main.js cannot. My only guess would be because it is a custom JavaScript file created by our head web developer, but I don't know why that would make a difference. (Cross-site scripting limitations?)
I link to it just like I do with all the other JavaScript files, right after our main wrapper (it's the 3rd from the bottom):
<script type="text/javascript" src="ui/2009/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="ui/2009/js/jquerytools/1.2.2/jquery.tools.min.js"></script>
<script type="text/javascript" src="ui/2009/js/jquery.cycle.all.min.js"></script>
<script type="text/javascript" src="ui/2009/js/main.js"></script>
<script type="text/javascript" src="ui/2009/js/jquery.jgfeed-min.js"></script>
<script type="text/javascript" src="ui/2009/js/hr.js"></script>
To troubleshoot follow these steps:
Check whether the file ui/2009/js/main.js is actually in that
location, if so be sure it doesn't have uppercase characters (the
server OS may be case sensitive)
Check whether the file main.js has the same permissions (i.e. chmod) as the other .js files (e.g. 755)
Check whether the file main.js is actually accessed (how do you know the file is
not accessed from your page in the dev server? It may be accessed but not working because of variable
conflicts with the .js you previously load, for instance). To do so,
you can a) check the server logs and see if you have a "not found"
error referred to the main.js file b) in main.js delete temporarily all
the content and print some simple output (either to screen with
document.write or to the javascript console with console.log)
I have my index.html at the root of my web host, and my javascript file is in a directory(JavaScript) which is also at the root. How can I link my index to the js file? I did the following, but it's not working: <script type="text/javascript" src="JavaScript/filename.js"></script> in the head. It works when I do the inline javascript
<script type="text/javascript" src="JavaScript/file.js"></script>
Loads the file.js in the subdirectory "JavaScript". It'll work unless a base href is specified.
Edit: I see now that's pretty much what you had. Should work. You got full code or URL?