Have this as a part in a ajax search page
index.php
$(document).ready(function(){
$('#user').keyup(function(){
var query = $(this).val();
if(query != '')
{
$.ajax({
url:"search.php",
method:"POST",
data:{query:query},
success:function(data)
{
$('#postList').fadeIn();
$('#postList').html(data);
}
});
}
});
});
search.php
$output .= '<div class="bild"><img src="'.$row["URL"].'" width="200" height="300" alt="'.$row["Titel"].'" onError="this.onerror=null;this.src="loading.jpg";"/></div>';
$output .= '</div>';
The problem is that i get a space in index.php when i activate it
this.src=" loading.jpg"
Anyone have any good explanation for why this is and also im happy if someone can get me in right path 🙂
Thanks
Need to get away the space ..
this.src="loading.jpg"
2
Answers
Here you have double quotes inside double quotes, change one of the to single quotes or escape the ones inside:
Try to do this:
or this:
or this:
One of them should fix it, just try with your code which one is best.
You quotations marks for loading.jpg are not escaped, thereby it is treating the loading.jpg as an attribute of the div tag and not as a src parameter of this. Replace the quotes around loading.jpg with
'
and it should work.I quickly typed the example in an interactive PHP shell to show you the effect.
First what your result was (you see that loading.jpg is in a different color highlighted):
And now my fix: