在WoodPress中使用jQueryPost和WooTheme';s画布5
除了在WoodPress中使用jQueryPost和WooTheme';s画布5,jquery,ajax,json,wordpress,post,Jquery,Ajax,Json,Wordpress,Post,除了$之外,我所有的javascript和jQuery代码都正常工作。我已经测试过直接发布到http://MYSITE.com/functions/course-functions.php通过其他方式获得以下有效的JSON响应: {"item":{"signedIn":true,"userID":"1","staySignedIn":"yes"}} 但是,每当我单击“登录”按钮时,javascript/jQuery都会正确地运行验证代码,但不会执行以下代码: $.post("http://MY
$之外,我所有的javascript和jQuery代码都正常工作。我已经测试过直接发布到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
});
你有没有想过我该怎么做?谢谢 @ehmad11我使用的是绝对URL,但它都在同一个域上。在我的PHP文件中,数据发布到的位置有以下代码:if($\u POST['type']=='signIn'){//code to execute}
。它还有if($\u POST['type']='signUp')
,等等。不确定type
是否是保留字,但我尝试将type
更改为formType
,但POST函数仍然不起作用。显然,我必须创建一个变通方法,以便在Wordpress中使用$.POST()
或$.ajax()
。我们看看能不能找到解决办法。