weixin_33728708 2015-11-12 19:36 采纳率: 0%
浏览 21

变量未传递给.load()

Can someone please point out to me what I am guessing is very simple error in my script.

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    var pn = $("#search");
    $("button").click(function(){
        $("#div1").load("data.asp?prodref= #result"+pn);
    });
});
</script>
</head>
<body>
<p id="search">92K002</p>
<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>

<button>Get External Content</button>

</body>
</html>

I am trying to pass the text from <p id="search">92K002</p> to .load()

  • 写回答

1条回答 默认 最新

  • ℙℕℤℝ 2015-11-12 19:39
    关注
    var pn = $("#search");
    

    Is an entire jQuery object. You need to grab the .text() from it.

    var pn = $("#search").text();
    

    An easy way to see this is to check the URL being loaded via the Network tab in your browsers console.

    评论

报告相同问题?