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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:11:22+00:00 2026-06-05T21:11:22+00:00

Assume that I have 2 .php files : index.php and ajax.php This is index.php:

  • 0

Assume that I have 2 .php files : index.php and ajax.php

This is index.php:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<META http-equiv=Content-Type content="text/html; charset=utf-8">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Website title</title>
<link href="css.css" rel="stylesheet" type="text/css" />
<script type="text/javascript"  src="jquery.js"></script>

</head>
<body>


<script type="text/javascript">
    ajax_register = function(){
        $.ajax({
            type: "post",
            url: 'ajax.php',
            dataType: 'json',
            data: "act=register",
            success: function(data){
                //var json = $.parseJSON(data);
                //alert(json);
                alert(data.result);

            },
            error: function(e){
                alert("Error : " + e);
            }
        });
    };

</script>

<form name="myForm" id="myForm" method="post">
    Your name :
    <input type="text" name="name" id="name" /> 
    <a href="javascript:void(0)" onclick="ajax_register()">Register</a>
</form>

</body>
</html>

And this is ajax.php:

<?php
$result = array("result"=>"Success");
echo json_encode($result);
exit;

But I always have “Error” alert dialog.

Look in Firebug, I see that the response data contains all html elements instead of only json data.

Try to send header as “json” by edit ajax.php :

<?php
header("Content-type: application/json");
    $result = array("result"=>"Success");
    echo json_encode($result);
exit;

But it doesnt work. The response header is always : Content-Type:text/html;

UPDATE

This is what ajax.php response:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">

    <META http-equiv=Content-Type content="text/html; charset=utf-8">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Website title</title>
    <link href="css.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript"  src="jquery.js"></script>

    </head>
    <body>


    <script type="text/javascript">
        ajax_register = function(){
            $.ajax({
                type: "post",
                url: 'ajax.php',
                dataType: 'json',
                data: "act=register",
                success: function(data){
                    //var json = $.parseJSON(data);
                    //alert(json);
                    alert(data.result);

                },
                error: function(e){
                    alert("Error : " + e);
                }
            });
        };

    </script>

    <form name="myForm" id="myForm" method="post">
        Your name :
        <input type="text" name="name" id="name" /> 
        <a href="javascript:void(0)" onclick="ajax_register()">Register</a>
    </form>
{"result":"Success"}

What do I wrong here?

Thanks for your time!

  • 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-06-05T21:11:24+00:00Added an answer on June 5, 2026 at 9:11 pm

    I only changed this LOC <script type="text/javascript" src="jquery.js"></script> to

    <script type="text/javascript"  src="http://code.jquery.com/jquery-latest.js"></script> 
    

    to check your code and its all working fine at my end ..check JS errors may be a case of JS conflicts. (Alerting Success for me). Let me know if problem still persist

    index.php CODE —

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <META http-equiv=Content-Type content="text/html; charset=utf-8">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Website title</title>
    <link href="css.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript"  src="http://code.jquery.com/jquery-latest.js"></script>
    
    </head>
    <body>
    
    
    <script type="text/javascript">
        ajax_register = function(){
            $.ajax({
                type: "post",
                url: 'ajax.php',
                dataType: 'json',
                data: "act=register",
                success: function(data){
                    //var json = $.parseJSON(data);
                    //alert(json);
                    alert(data.result);
    
                },
                error: function(e){
                    alert("Error : " + e);
                }
            });
        };
    
    </script>
    
    <form name="myForm" id="myForm" method="post">
        Your name :
        <input type="text" name="name" id="name" /> 
        <a href="javascript:void(0)" onclick="ajax_register()">Register</a>
    </form>
    
    </body>
    </html>
    

    ajax.php CODE —

    <?php
    $result = array("result"=>"Success");
    echo json_encode($result);
    exit;
    

    Alerting Success on clicking at register.

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

Sidebar

Related Questions

I have a question regarding static function in php. let's assume that I have
Assume that I have this piece of code: @interface Foo : NSObject { Bar
I have a session variable that I set like this: <?php $token = md5(uniqid(rand(),
Let's say we have the following schema: root/ application/ -public/ index.php css/ img/ javascript/
I have a php system that uploads images and suffixes their files names with
I have included a file named test.php in the file index.php lets assume index.php
This is what I have so far: RewriteRule ^([A-Za-z0-9_]*)/?$ index.php?page=$1 [NC] RewriteRule ^([A-Za-z0-9_]*)/([A-Za-z0-9_]*)/?$ index.php?page=$1/$2
Assume that I have a HTML file as myweb.html in C:\ directory. And some
Assume that we have multiple arrays of integers. You can consider each array as
Assume that I have the ItemSource bound and i am getting the data. Now

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.