1

I'm using AJAX to submit POST data to a parser file

$.ajax({
    type: 'POST',
    url: '<?php echo AJAX_DIR; ?>/parser.php',
    data: data,
    etc......

On the submitting page, I can echo/use $user->data()->id; just fine. If I browse to the parser file directly I can also echo/use $user->data()->id; just fine. However, when I submit the AJAX, the $user object is empty.

I've also tried using a $_SESSION variable to get my data to the AJAX parser and the same behavior is present (good on the page and parser file when I browse to it, but empty upon AJAX submission).

Any ideas?

EDIT for showing the first few lines of the parser file...

<?php

//For allowing this to be accessed from anywhere within users.mysite.com
header('Access-Control-Allow-Origin: https://users.mysite.com');

//Userspice requires
require_once '../../init.php';

Note: The init.php file starts the session as the first thing.

4
  • Can we see your parser.php code. And at first look what i feel is that your parser.php might be looking for a cookie /header in the ajax request which might be causing the issue. to be clear is the $user object retrieved from session ? Commented Oct 7, 2017 at 15:29
  • @BlackBurn027: I edited my post. Thanks. Commented Oct 7, 2017 at 16:15
  • Can you show $user line Commented Oct 7, 2017 at 16:20
  • @Osama: I'm not sure what you mean. $user is an object. OVerall, the issue seems to be that I'm losing the entire session when submitting ajax, but it's fine when I browse to the parser file directly. Commented Oct 7, 2017 at 16:37

1 Answer 1

1

Got it figured out. If you are sending ajax from sub.domain.com and parsing it at domain.com/sub/parser.php it breaks. I fixed it by telling the ajax submit to parse the info. at sub.domain.com/parser.php.

Hope that helps someone else.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.