1

I want to set the jQuery load target. The below code is work.

<script>
$(document).ready(function() {

$(".first").click(function(){
var str=$(this).attr("value"); /

$(".sencond").hide();  
$("#shows").html("wait ... ");
$("#shows").show();

$("#shows").load('load.php?str='+str); 

})

})
</script>

I want to change the load target to $("#shows").load("'+str+'.php"); But this isn't work.

What 's wrong?

2
  • please try out solution $("#shows").load( str+ ".php") Commented May 17, 2018 at 6:58
  • is that worked ? Commented May 17, 2018 at 8:39

3 Answers 3

1

can you do like this , there is not need of quote ('str') around str.

$("#shows").load( str+ ".php")

problem with $("#shows").load("'+str+'.php"); it will generate string as 'strvalue'.php and that page will not be found.

Sign up to request clarification or add additional context in comments.

Comments

1

Here is working code:

<script>
$(document).ready(function() {

$(".first").click(function(){
var str=$(this).attr("value"); 

$(".sencond").hide();  
$("#shows").html("wait ... ");
$("#shows").show();

$("#shows").load(str+'.php'); 

})

})
</script>

make sure load php page should be there!!

Comments

1

Use js template string

$("#shows").load(`${var}.php`)

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.