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 7680643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:09:43+00:00 2026-05-31T18:09:43+00:00

I am new to PHP and JavaScript development, I am trying to execute this

  • 0

I am new to PHP and JavaScript development, I am trying to execute this code but it fails:

<?php
if(isset($_POST['username']) and isset($_POST['password'])) {

 // do logic for logining in (usually query your db)
if ($_POST['username'] == 'test' && $_POST['password'] == 'test') {
$data['success'] = true;
$data['message'] = 'Login succesful';
} else {
$data['success'] = false;
$data['message'] = 'Login failed';
}
// return json
echo json_encode($data);

}
?>

Here is the JavaScript file:

<script>
    $(document).ready(function() {
    alert("dddd");
        $('#loginForm').submit(function() {
            $('#output').html('Connecting....');
            var postTo = 'http://localhost/Login/login.php';
            alert(postTo);
            $.post(postTo,{username: $('[name=username]').val() ,   password: $('[name=password]').val()} , 
                function(data) {
                
                    if(data.message) {
                        alert(data);
                    } else {
                        $('#output').html('Could not connect');
                    }
                
                },'json');
            
            return false;
        });
    });
</script>

Please help.

  • 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-31T18:09:45+00:00Added an answer on May 31, 2026 at 6:09 pm

    Funnily enough it works for me in Firefox. I had the problem with IE a while back and the solution was to add the correct headers to the top of the php script:

    <?php
    header('Cache-Control: no-cache, must-revalidate');
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    header('Content-type: application/json');
    ...
    

    EDIT: Reproduced it by calling it from another machine. try to change var postTo = 'http://localhost/test/test.php'; to var postTo = 'test/test.php'; .

    here’s what I tested with ( I woud recommend you use firebug and console.log() instead of alert()):

    <html>
    <head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script>
    $(document).ready(function() {
     $('#output').html('somestuff');
    
        $('#loginForm').submit(function() {
            $('#output').html('Connecting....');
            var postTo = 'http://localhost/test/test.php';
            //alert(postTo);
            $.post(postTo,{username: $('[name=username]').val() ,   password:  $('[name=password]').val()} , 
                function(data) {
    
                    if(data.message) {
                       //  console.log(data);
                        $('#output').html('Ya got it: '+ data.message);
                    } else {
                        $('#output').html('Could not connect');
                    }
    
                },'json');
    
            return false;
        });
    });
    </script>
    </head>
    
    <body>
    <form id="loginForm">
        <input type="text" name="username" value="test"/>
        <input type="text" name="password" value="test"/>
        <input type="submit"  />
    </form>
    <div id="output"></div>
    </body>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to web development, I've learned php, mysql and javascript. I'm trying
I've been using PHP for too long, but I'm new to JavaScript integration in
I am new to PHP and trying to get the following code to work:
I have the following html/php/javascript code: <?php $textBox1 = $_POST[textBox1]; ?> <html> <head> </head>
Ok, so I'm new to C# Windows App development coming from ColdFusion, PHP, Javascript.
So I am still somewhat new to PHP, MySQL, and Javascript but I have
I am new into Facebook application development and also newbie about JavaScript and PHP
Rather new to php, so sorry if this seems stupid. I'm really copying a
I am pretty new to php, but I am learning! I have a simple
I'm trying to find out if a string contains css code with this expression:

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.