1

Why is it that when I remove //code.jquery.com/jquery-1.9.1.js the site runs my AJAX requests. Though when I have it, I cannot access the JQuery UI datePicker?

<head>    
<link rel="stylesheet" type="text/css" href="CSS/custom.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<link href='http://fonts.googleapis.com/css?family=Cabin:400,600' rel='stylesheet'     type='text/css'>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js" type="text/javascript"></script>

<script type="text/javascript" src='js/custom.js'></script> 
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
</head>

Very bizarre - I posted the google api in a certain place that magically made it work. Anyone know why? I reposted by code here: Why did this sequence of Jquery/Google API requests work?

Community
  • 1
  • 1
glewis15
  • 47
  • 10
  • you don't needed to import two jquery's. you can follow this: first import the `jquery.js` then import `custom.js` because i hope you are doing ajax request in the `custom.js` and it need jquery – suhailvs Mar 15 '14 at 07:40
  • please see my answer. i have added comments, so that you may understand – suhailvs Mar 15 '14 at 07:42

2 Answers2

1

you are using two jquery and jquery ui. You must use one. since .min.js and .js are same. min.js is just the compressed version of .js

Ie the below code is enough:

<head>    
<link rel="stylesheet" type="text/css" href="CSS/nudgeme.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<link href='http://fonts.googleapis.com/css?family=Cabin:400,600' rel='stylesheet'     type='text/css'>
<link rel="stylesheet" type="text/css" href="CSS/nudgeme.css">

<!-- First import jquery -->
<script src="//code.jquery.com/jquery-1.9.1.js"></script>

<!-- Then Jquery library imports -->
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>    
<script type="text/javascript" src='js/nudgeme.js'></script>

<!-- Then Custom script that uses the above libraries-->
<script type="text/javascript" src='js/custom.js'></script> 
</head>

Use custom.js below all other imports. because javascript executed from top to bottom. so for example if your script uses a javascript function(for eg: jquery $) and you write the code above the import of jquery.js it simple won't work.

suhailvs
  • 20,182
  • 14
  • 100
  • 98
  • Thank you Suhail for the quick response. Though for some reason without the link ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js the ajax request will not load the received data. With it, the datePicker still will not load. – glewis15 Mar 15 '14 at 06:45
  • @user3250682 it is becuase you added line ` ` above the line ``. you just need to add it below `jquery.js`. that is it – suhailvs Mar 15 '14 at 06:48
  • I see what you mean, though the datePicker still refuses to show. Where would the google api fall into your provided code? – glewis15 Mar 15 '14 at 07:00
  • Very bizarre. No errors in the console. Seem to have made it work! I'll post what I did below - but if you know why please explain. I (as I'm sure other would) love to know why it worked... – glewis15 Mar 15 '14 at 07:09
  • http://stackoverflow.com/questions/22420812/why-did-this-sequence-of-jquery-requests-work – glewis15 Mar 15 '14 at 07:17
  • @user3250682 because javascript code will executed from top to bottom. i mean it execute first line. then second line, then third...... – suhailvs Mar 15 '14 at 07:33
1

Ok i did not found <!DOCTYPE html>(so it is not html5) in your code and so i recommend you to mention type="text/javascript" in you script tag

<script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

for reference link

Community
  • 1
  • 1
kamesh
  • 2,374
  • 3
  • 25
  • 33