0

Here is the Code. I've already researched about it and so far, haven't found the right solution. Any help would be much appreciated. Thanks.

    <script type="text/javascript" src="{%static 'javascript/jquery-3.1.1.js'%}"></script>
    <script type="text/javascript">

  $(document).ready(function(){
   $("#itemid").change(function(){
    var itemid = $(this).val();
    var func_url = '/get_itemdetails/' + itemid +'/';
    $.ajax({
     type:"GET",
     url: func_url,
     dataType:"json",
     success: function(data){
      console.log(data);
     }
    });
   });
  });
  
 </script>
Bigboss
  • 355
  • 1
  • 3
  • 17
  • http://api.jquery.com/jquery.ajax/, try the `fail` callback and see what the error. `$` is global should not have this issue. Check `$` inside your console – XY L Feb 23 '17 at 01:27
  • http://stackoverflow.com/questions/18271251/typeerror-ajax-is-not-a-function – nathan hayfield Feb 23 '17 at 01:27
  • 1
    not all versions of jquery come with $.ajax function. Search in your version to see if it has it. – nathan hayfield Feb 23 '17 at 01:30
  • it is working. i tried this window.onload = function() { if (window.jQuery) { // jQuery is loaded alert("Yeah!"); } else { // jQuery is not loaded alert("Doesn't Work"); } } and it loads properly. – Bigboss Feb 23 '17 at 01:31
  • Could be another library is assigning the `$` variable. Try changing your first line to `jQuery(function($) {` – Phil Feb 23 '17 at 02:27
  • already tried it also. still getting the same error. – Bigboss Feb 23 '17 at 02:30

1 Answers1

2

Below is the latest script header for Google's hosted CDN which allows for the $.ajax Function:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script type="text/javascript">

  $(document).ready(function(){
   $("#itemid").change(function(){
    var itemid = $(this).val();
    var func_url = '/get_itemdetails/' + itemid +'/';
    $.ajax({
     type:"GET",
     url: func_url,
     dataType:"json",
     success: function(data){
      console.log(data);
     }
    });
   });
  });
  
 </script>
Chris Cruz
  • 1,829
  • 13
  • 15