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.

    评论

报告相同问题?

悬赏问题

  • ¥15 已知平面坐标系(非直角坐标系)内三个点的坐标,反求两坐标轴的夹角
  • ¥15 webots有问题,无响应
  • ¥15 数据量少可以用MK趋势分析吗
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上