Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6069219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:47:56+00:00 2026-05-23T09:47:56+00:00

I am new to AJAX/jQuery with PHP. I am trying to call a PHP

  • 0

I am new to AJAX/jQuery with PHP.

I am trying to call a PHP script via AJAX using XMLHttpRequest or jQuery. In both cases the call fails because the php file I am calling into contains on the very first row the following check

if (!defined("SOMETHING")) { die("Error. You cannot access this file directly");}

which causes that my call fails, because this variable is not defined in this case as I am calling from the outside. This condition just checks if the caller is the same web application or wheather the call comes from outside (then it will be denied).

Is there a workaround for it without removing this check? Can I somehow set this expected variable using AJAX/jQuery?

Is there a way how to call specific PHP method via AJAX without calling into the whole PHP file?

Thanks in advance
Tomas

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:47:56+00:00Added an answer on May 23, 2026 at 9:47 am

    Hmm… you can do it, but I am not sure if this is secure or the way you would like it to be.

    Your jQuery should post a variable with GET or POST, which you should check on PHP side. If you have received that variable, then define SOMETHING.

    Here is your jQuery, using the POST method:

    $.post('ajax.php', {SOMETHING: true}, function(ret){
        // do whatever you like with the return here
    });
    

    Here is your PHP, which will define SOMETHING if it receives a $_POST request with the variable SOMETHING in it.

    <?php
    if(isset($_POST['SOMETHING'])){
        define('SOMETHING', true);
    }
    if (!defined("SOMETHING")) { die("Error. You cannot access this file directly");}
    
    // do anything you like here
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use jQuery's get function to call my php script. The php
I'm using a jQuery ajax json call to retrieve a 3 dimensional PHP array
I'm trying to pass a variable via jquery ajax call. I'm not exactly sure
I'm new to jQuery / AJAX. I'm trying to send single input with jquery/ajax/php.
I am writing an ajax script in jQuery. The script gets new or previous
I have application that brings response via Ajax and creates 5-20 new jQuery click
I'm very new at AJAX calls from jQuery and I'm a bit stuck trying
I've been trying to get a script to work that calls a PHP file
I am trying to send html via jQuery's $.ajax() method, and then dump the
Using JQuery, and still a little new to it, trying to change an Link

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.