Using jQuery POST in WordPress with WooTheme’s Canvas 5

All of my javascript and jQuery code is working except for $.post. I have tested posting directly to http://MYSITE.com/functions/course-functions.php via other means and gotten the following valid JSON response:

{"item":{"signedIn":true,"userID":"1","staySignedIn":"yes"}}

However, whenever I click the sign-in button the javascript/jQuery properly runs through the validation code, but then doesn’t do the following code:

Read More
$.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');

I use the following wrapper to make jQuery ($) work in WordPress:

jQuery(document).ready(function($) {
  //my jQuery Code
});

Any thoughts on how I can get this working? Thanks!

Related posts

Leave a Reply