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 :
- check if jquery has been added in index.html (or whatever name main html has) file.
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 }
also, don't forget check if document object ready, if going fetch value html inputs.
$( document ).ready(function() { console.log( "ready!" ); });
Comments
Post a Comment