我所有的 javascript 和 jQuery 代码都在工作,除了$.post
. 我已经测试了通过其他方式直接发帖http://MYSITE.com/functions/course-functions.php
并得到以下有效的 JSON 响应:
{"item":{"signedIn":true,"userID":"1","staySignedIn":"yes"}}
但是,每当我单击登录按钮时,javascript/jQuery 都会正确运行验证代码,但不会执行以下代码:
$.post("http://MYSITE.com/functions/course-functions.php", {
type: 'signIn',
email: email,
password: password,
staySignedIn: staySignedIn },
function(data) {
var response = data.item;
console.log(response);
if (response.SignedIn == false) {
$('#alerts').html('Oops! The email and password you used did not work. Please try again.').show();
}
else {
if (response.staySignedIn == 'yes') {
localStorage.staySignedIn = 'yes';
localStorage.userID = response.userID;
}
sessionStorage.userID = response.userID;
sessionStorage.signedIn = 'true';
var url = 'http://MYSITE.com/courses?userID=' + response.userID + autoClaimCodeURLvariable;
window.location = url;
}
},'json');
我使用以下包装器使 jQuery ($) 在 Wordpress 中工作:
jQuery(document).ready(function($) {
//my jQuery Code
});
关于如何让这个工作的任何想法?谢谢!