I have a function:
def productdetails():
if session.login == False:
redirect(URL('petscart','default','login'))
myproducts=db(db.Products.product_number > 0).select()
return dict(products=myproducts)
A html file with:
<form>
<input id="product" type="button" value="Add to Cart" onclick="textAjax({{=product['product_number']}})"/>
</form>
And a JS function (textAjax) that takes the product_number passed to it and does some funky stuff, passes some data to a web2py controller.
The strange part is {{=product['product_number']}} is passing an integer in this case life is good. if I try to pass a string instead for example {{=product['product_name']}}
The javaScript will show a reference error, Reference Error "value" cannot be defined.
I will paste the JS too:
<script type="text/javascript">
function textAjax(id){
jQuery.ajax({
type:'GET',
url:'/test/default/addtocart',
data: {
product:id
},
timeout: 1000,
success: function(msg) {
console.log(msg);
jQuery('#output').html(msg)
},
error: function(objAJAXRequest, strError){
$( "#ajaxerror" ).append( " AJAX error:" + strError );
}
});
}
</script>