Answer the question
In order to leave comments, you need to log in
How to correctly enter a variable into a script?
Good day.
There is a variable, let's say xyz = "www.site.com/wp-content/themes/Stars/";
How to enter it before src in this line? So that she adds the address I need?
$("#img").attr("src",response);
Here is a sample code to do this:
$(document).ready(function(){
$("#but_upload").click(function(){
var fd = new FormData();
var files = $('#file')[0].files[0];
fd.append('file',files);
$.ajax({
url: '/wp-content/themes/Stars/upload.php',
type: 'post',
data: fd,
contentType: false,
processData: false,
success: function(response){
if(response != 0){
$("#img").attr("src",response);
$(".preview img").show(); // Display image element
}else{
alert('file not uploaded');
}
},
});
});
});
Answer the question
In order to leave comments, you need to log in
So?
var url = " https://www.site.com/wp-content/themes/Stars/ ";
$("#img").attr("src", url + "image1.png");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question