troubleshooting Question

dynamic image

Avatar of Marco Gasi
Marco GasiFlag for Spain asked on
JavaScript
26 Comments1 Solution263 ViewsLast Modified:
Hi all.
Okay, I fought hard: now, I surrend!
In a page I do an ajax call to a script which returns an array containing all products of a given category. In the array are the image name hold in the database, but not always the image exists. SO I do another ajax call to a php script which return true or files accordingly: if the script returns false a placeholder should be used.
My not-working code is this:

	var listProductsPerSubcategory = function (dest, subcatid)
	{
		$.ajax({
			type: 'post',
			url: 'scr_list_products_per_subcategory.php',
			data: {subcatid: subcatid},
			dataType: 'json',
			success: function (result)
			{
				var lst = '<script>$(function() {$( ".imgres" ).aeImageResize({ height: 150, width: 100 });})</script>';
				$.each(result, function (k, v)
				{
					var img = v['pictures'];
					$.ajax({
						type: 'post',
						url: 'scr_file_exists.php',
						data: {f: img},
						success: function (result)
						{
							if (result === false)
							{
								img = 'nopic';
							}
							else
							{
								img = v['pictures'];
							}
						},
						error: function ()
						{
							img = 'nopic';
						}
					});
					lst = lst + '<div class="productFrame">';
					lst = lst + '<div class="imgwrapper"><img class="imgres" src="../pictures/' + img + '.jpg" /></div>';
					lst = lst + v['prod_code'] + '<br>';
					lst = lst + v['prod_name'] + '<br>';
					lst = lst + '</div>';
				});
				$(dest).html(lst).fadeIn('slow');
			},
			error: function (result)
			{
				$(dest).html(result).fadeIn('slow');
			}
		});
	};

Shortly, the img valus remains just the same even if the php script returns false.
Please, help me to understand!!!
Thank you all in advance.
Marco
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 26 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 26 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros