0

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>
1
  • No one :( as an answer Commented Oct 12, 2014 at 8:16

1 Answer 1

1

A sting must be wrapped in quotes:

textAjax('{{=product['product_number']}}')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.