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

  • Home
  • SEARCH
  • 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 6148597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:18:35+00:00 2026-05-23T19:18:35+00:00

So from my php, I am echoing {error:1}: $(document).ready(function(){ $(‘#form’).submit(function(e){ register(); }); }); function

  • 0

So from my php, I am echoing {error:1}:

$(document).ready(function(){
    $('#form').submit(function(e){
        register();
    });
});

function register(){
    $.ajax({
        type:"POST",
        url:"submit.php",
        async : false,
        data: $('#form').serialize(),
        dataType: "json",
        success: function(msg){
            if(parseInt(msg.error)==1){
                window.location="index.html";
            }
            else if(parseInt(msg.error)==0){  
                $('#error_out').html(msg.error);
                e.preventDefault();
            }
        }
    });
}

But it does not want to redirect. Instead it return “submit.php” with 1 echoed.

  • 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-23T19:18:36+00:00Added an answer on May 23, 2026 at 7:18 pm

    Well, you can’t just have a return of 1, as that wouldn’t be JSON. If you’re just returning ‘1’ and doing a parseInt on it, set the dataType to ‘html’.


    If you want JSON, do this in your PHP:

    $return = array('code'=>1);
    echo json_encode($return);
    

    Your ‘success’ function would look like this:

    if(msg.code==1){
        window.location="index.html";
    }
    else if(msg.code==0)
    {
        $('#error_out').html(msg.code);
        e.preventDefault();
    }
    else 
    { 
       // handle any other return value.
    }
    

    Ok, my fault for not reading the problem properly. The problem is that you’re submitting the form, and not cancelling it properly. Do this in your event handler:

    $(document).ready(function(){
        $('#form').submit(function(e){
            e.preventDefault();
            register();
        });
    });
    

    You can remove the one in your failure case. That one doesn’t do anything, since the stack would have already cleared by the time the async function came back (if it did at all).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This example is from php.net: <?php function Test() { static $a = 0; echo
I come from PHP world, where declaring a function in the middle of a
To return an error from a $.ajax call, there's gotta be a better way
Suppose I am echoing random data from PHP to browser. Total amount of random
From php.net: <html> <?php /* This will give an error. Note the output *
Coming from PHP with some Java Struts 2.0 experience any tips/tricks on learning GWT?
Im porting a project from php to java. The project is a web-app based
I want to execute a php-script from php that will use different constants and
I am generating the json from PHP.
I need to perform a HTTP GET from PHP. More specifically, from within /index.php

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.