模板文字为空
template literal gets null
我在不同的 jquery 函数中有一些模板文字。其中一些正在工作。但是这个块没有执行。
function viewUserDetails(data) { // gets integer {1,2,3,...}
let x = ``; // ""
let y = ``; // ""
$.ajax({
type : "GET",
url : 'http://localhost/bugs_javascript/api/public/getSingleUser.php',
data : {
"id" : data // gets value {1,2,3,...}
},
dataType : 'json',
contentType : 'application/json',
success: function (e) {
console.log("success: "+e); // logs the returned JSON object
x += `<label for="title">Full Name</label>
<input type="text" class="form-control"
id="updateUserName" oninput="checkName('update')"
value="${e.name}">
<span id="uNameMsg"></span>
<br>
<label for="title">Unique ID</label>
<input type="textarea" class="form-control" id="updateUserUnique" rows="5"
value="${e.nick_name}"
oninput="checkUnique('update', ${e.nick_name})">
<span id="uUniqueMsg"></span>
<br>
<label for="title">Email</label>
<input type="text" class="form-control"
id="updateUserEmail"
value="${e.email}"
oninput="checkEmail('update', ${e.email})">
<span id="uEmailMsg"></span>
<br>
<button class="btn btn-success"
id="editUserFButtton"
onclick="updateUser(${e.id})">Update
Record</button>
<span id="updateUserBtnMsg"></span>`; // x = ""
y = `User Registered on: ${e.registration_date}`; // y = ""
},
error : function (e) {
console.log("error: "+e);
}
});
$("#modalFlashContent").append(x); // "" null
$("#modalFlashHeader").text(y); // "" null
} // Not working. Some prooblem
这应该在 AJAX 请求发生时在 x 和 y 变量中给出一个 HTML 块。但它给出了 null.
在函数的底部,x 和 y 将为空,因为 ajax 调用的成功将比您分配 x 和 y 的时间晚 return。你需要把
$("#modalFlashContent").append(x);
$("#modalFlashHeader").text(y);
在成功调用的底部。
我在不同的 jquery 函数中有一些模板文字。其中一些正在工作。但是这个块没有执行。
function viewUserDetails(data) { // gets integer {1,2,3,...}
let x = ``; // ""
let y = ``; // ""
$.ajax({
type : "GET",
url : 'http://localhost/bugs_javascript/api/public/getSingleUser.php',
data : {
"id" : data // gets value {1,2,3,...}
},
dataType : 'json',
contentType : 'application/json',
success: function (e) {
console.log("success: "+e); // logs the returned JSON object
x += `<label for="title">Full Name</label>
<input type="text" class="form-control"
id="updateUserName" oninput="checkName('update')"
value="${e.name}">
<span id="uNameMsg"></span>
<br>
<label for="title">Unique ID</label>
<input type="textarea" class="form-control" id="updateUserUnique" rows="5"
value="${e.nick_name}"
oninput="checkUnique('update', ${e.nick_name})">
<span id="uUniqueMsg"></span>
<br>
<label for="title">Email</label>
<input type="text" class="form-control"
id="updateUserEmail"
value="${e.email}"
oninput="checkEmail('update', ${e.email})">
<span id="uEmailMsg"></span>
<br>
<button class="btn btn-success"
id="editUserFButtton"
onclick="updateUser(${e.id})">Update
Record</button>
<span id="updateUserBtnMsg"></span>`; // x = ""
y = `User Registered on: ${e.registration_date}`; // y = ""
},
error : function (e) {
console.log("error: "+e);
}
});
$("#modalFlashContent").append(x); // "" null
$("#modalFlashHeader").text(y); // "" null
} // Not working. Some prooblem
这应该在 AJAX 请求发生时在 x 和 y 变量中给出一个 HTML 块。但它给出了 null.
在函数的底部,x 和 y 将为空,因为 ajax 调用的成功将比您分配 x 和 y 的时间晚 return。你需要把
$("#modalFlashContent").append(x);
$("#modalFlashHeader").text(y);
在成功调用的底部。