[英]ajax is loading both divs on the page instead of specified div
I have a PHP page with the following two divs, and I am trying to load the content with a click event here and then conditional: 我有一个包含以下两个div的PHP页面,并且我试图在此处使用click事件然后按条件加载内容:
if (ballResult == 'W') { // processing wide $.ajax({ url: "loads/scorer_soft_load.php #extrWideLoad", cache: false, success: function(html) { $("#scoreBt").html(""); $('#scoreBt').append(html); }, // call back function after ajax request complete complete: function() { } }); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="extraScoreLoad"> <h3 class="gmu-heading" id="extrHeading"><span class="badge badge-secondary">Any extra</span></h3> <button>nb</button> </div> <!------load for wide--------> <div id="extrWideLoad"> <h3 class="gmu-heading" id="extrHeading"><span class="badge badge-secondary">Any extra</span></h3> <button>w</button> </div>
I am doing the same for the other div just changing the URL to loads/scorer_soft_load.php #extraScoreLoad
. 我对其他div所做的相同,只是将URL更改为
loads/scorer_soft_load.php #extraScoreLoad
。
url: "loads/scorer_soft_load.php #extrWideLoad"
You're trying to apply a selector in the URL. 您正在尝试在URL中应用选择器。 (Not to be confused with a fragment identifier.) URLs don't really work like that.
(不要与片段标识符混淆。)URL并不是那样工作的。 It's going to return all of the content, you'd need to apply a selector after you receive the content.
它会返回所有内容,您需要在接收到内容后应用选择器。 For example:
例如:
$.ajax({
url: "loads/scorer_soft_load.php",
cache: false,
success: function(html){
$("#scoreBt").html("");
var filteredHtml = $('#extrWideLoad', html); // <--- here
$('#scoreBt').append(filteredHtml);
}
});
i have use this technique with .load and it have worked in past.
我已经将这种技术与.load结合使用,并且它在过去一直有效。
That's because .load()
does this client-side selector logic for you . 这是因为
.load()
为您执行了此客户端选择器逻辑 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.