Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
How do I fix Undefined array key "token" in C:\xampp\htdocs\TPO\registered.php on line 2?

I would like to send data from javascript to php but this "Undefined array key "token" in C:\xampp\htdocs\TPO\registered.php on line 2" is trigger in my php file.

JavaScript function

function doSomething(Acronym) { 
 $.post('registered.php', {token: "Hello"});
 console.log($(Acronym).data('id'))
} 

registered.php

<?php
$variable = $_POST['token'];
echo($variable);
?>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use jQuery Ajax for posting data to the PHP files by javascript.

This can be your js file:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" ></script>
<script>
    var vars = {
        'token': 'Hello',
    };
    var userStr = JSON.stringify(vars);
    $.ajax({
        url: 'registered.php',
        type: 'post',
        data: { vars: userStr },
        success: function (response) {
            console.log(response);
        }
    });
</script>

And this is your PHP file:

<?PHP
    $vars = $_POST['vars'];
    $variable = json_decode($vars, true);
    echo($variable);
?>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!