javascript - $.ajax is not a function? -


i have started learn javascript , working on small project. having error stating "$.ajax not function". endpoint, token, , body defined variables.

var $ = require('jquery'); $.ajax({     type: 'post',     url: endpoint + token,     contenttype: 'application/json',     data: json.stringify(body),     success: function(data, status) {         console.log(data);         console.log(status);     },     error: function(jqxhr, status, errorthrown) {         console.log(errorthrown);         console.log(status);         console.log(jqxhr);     } }); 

anyone see problem have?

2 possible reasons :

  1. check if jquery has been added in index.html (or whatever name main html has) file.
  2. if above not relate problem, need put check i.e. jquery available you, below code :

    if(window.jquery)     {        ...do stuff here      }       else{             ... handle according need here            } 
  3. also, don't forget check if document object ready, if going fetch value html inputs.

     $( document ).ready(function() {     console.log( "ready!" );  }); 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -