0

I keep getting this error, but I can not figure it out what the problem seems to be. Apparently the error is in the line of currentProduct.find()

var $productTemplate = $(".product-item");
$.ajax({
    url: 'data/applicationLayer.php',
    type: 'POST',
    dataType: 'json',
    contentType: "application/x-www-form-urlencoded",
    data: {
        action: "MOSTRARIMAGENES",
    },
})
.done(function(jsonResponse) {
    $.each(jsonResponse, function(index, val) {
        if (jsonResponse.length) {
            $("#initialProductMessage").remove();
            var $currentProduct = $productTemplate.clone(true);
            $currentProduct.find('.producto1').html(val.nombre + "<br>" + "<img src="val.foto" width="200" height="400">");
            $currentProduct.show();
            $("#products-display").prepend($currentProduct);
        }
    });
})
3
  • You're missing some + to concatenate your string with the val.foto Commented Nov 14, 2016 at 14:33
  • Escape the quotes in the <img> html snippet you concatenate with val.nombre and "<br>" Commented Nov 14, 2016 at 14:35
  • Should this question be moved to es.stackoverflow.com? Commented Nov 14, 2016 at 14:42

1 Answer 1

1

You're missing some + to concatenate your string with the val.foto. You also should escape some quotes to wrap the values. Try this:

$currentProduct.find('.producto1').html(val.nombre + "<br><img src=\"" + val.foto + "\" width=\"200\" height=\"400\">");

Or using single quotes to avoid escaping entirely:

$currentProduct.find('.producto1').html(val.nombre + '<br><img src="' + val.foto + "' width="200" height="400">');
Sign up to request clarification or add additional context in comments.

4 Comments

Beat me by just a bit!!
Yup, but there's more escaping to do: the width and height attributes. Or simply use single quotes for these strings to avoid escaping.
@RoryMcCrossan you're welcome - We're all here to help!
@RoryMcCrossan actually, there's still one double quote unedited at the very end! I can't edit it because edits must have at least 6 characters :/

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.