javascript - Jquery: Ajax Post not functioning with JinJa Templating -


objective: objective quite simple. should able click button , post information database.

problem: clicking button doesn't post database.

setup: using flask framework, jquery, , jinja templating.

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.0/js/bootstrap.min.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript" src="/static/js/bootstrap.min.js"></script>  <script type="text/javascript">     (function () {      "use strict";     $(document).ready(function(){     var script_root = "";        $('#cart').live('click', function(){     var asin = $(this).attr('class').split(' ')[3];             $.ajax({                 url: script_root + '/api' + '/mattel' + '/' + asin,                 datatype: 'json',                 error: function() {                     alert("no dice!");                 },                 success: function(data) {                     console.log(data.product, data.asin);                     $.ajax({                         type: "post",                         contenttype: "application/json; charset=utf-8",                         url: script_root + '/api/shopping',                         data: json.stringify({"asin":data.asin, "user":"lwgray@gmail.com", "store":data.store, "product":data.product}),                         error: function() {                             alert("no dice, again!");                         },                         success: function(data) {                             console.log(data.product);                             },                         datatype: 'json'                     });                 }             });         });      }); }); </script>     

question: question you'll going wrong? used work before.

this doesn't work because you're using .live() , jquery 1.11. .live() replaced .on() in jquery 1.9.

http://api.jquery.com/on/

<script type="text/javascript">     (function () {      "use strict";     $(document).ready(function(){     var script_root = "";        $('#cart').on('click', function(){     var asin = $(this).attr('class').split(' ')[3];             $.ajax({                 url: script_root + '/api' + '/mattel' + '/' + asin,                 datatype: 'json',                 error: function() {                     alert("no dice!");                 },                 success: function(data) {                     console.log(data.product, data.asin);                     $.ajax({                         type: "post",                         contenttype: "application/json; charset=utf-8",                         url: script_root + '/api/shopping',                         data: json.stringify({"asin":data.asin, "user":"lwgray@gmail.com", "store":data.store, "product":data.product}),                         error: function() {                             alert("no dice, again!");                         },                         success: function(data) {                             console.log(data.product);                             },                         datatype: 'json'                     });                 }             });         });      }); }); </script>  

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -