location.href显示整个页面



我将数据插入数据库,并在不刷新页面的情况下在页面上显示数据。

我尝试了$("#e-empListwrap").load(location.href + "#e-empListwrap");,但它在我的页面上显示了整个页面。

$("form[name='emp']").validate({
rules: {
//rules
},
submitHandler: function(form) {
var form = $('form[name="emp"]').get(0);
var formData = new FormData(form);
$.ajax({
url: baseUrl + "/controller/emp_control.php",
type: "POST",
dataType: 'json',
data: formData,
contentType: false,
cache: false,
processData: false,
success: function(data) {
$('form[name="emp"]')[0].reset();
$('#modal-addemp').modal().hide();
$("#e-empListwrap").load(location.href + "#e-empListwrap");
},
}); // AJAX Get Jquery statment
}
});

HTML

<div class="e-empListwrap mt-4" id="e-empListwrap"><ul></ul></div>
// The below is the script when refersh the page then it will call the ajax and get the the and display on the page.
<script>
fetchEMPsaved_data();
function fetchEMPsaved_data(){
$.ajax({
url:'controller/developer_control.php',
type: "post",
dataType: "json", 
data: { action: "fetchEMPsaved_data"},
success: function(data) {
$("#e-empListwrap ul").append(data);
}
});
}
</script>

url后面,url和CSS目标之间缺少一个空格:

$("#e-empListwrap").load(location.href + " #e-empListwrap");

否则,jquery将其作为url的锚点处理,而不是作为元素ID。您正在加载url.html#element,但要grep一个element/css目标,而不是整个页面,语法应该是url.html #elementOrTarget,中间有空格。

最新更新