PHP why my Ajax return value is 1 why does the foreground receive the HTML code for the exact entire page of pages displayed by alert (data)

Source: Internet
Author: User
Tags smarty template
PHP why my Ajax return value is 1 why does the foreground receive the HTML code of the exact entire page page that the alert (data) displays (I used the Smarty also returns the value of the page in the Smarty template)


Reply to discussion (solution)

Add exit after PHP output 1;

Or not! Ask for guidance

That's what you do with Ajax requests.
Usually you just do business logic

Can you say something more specific?

To see the admin.php code

Class admincontroller{

Public Function __construct () {
Session_Start ();
if (! ( Isset ($_session[' username '))) && (PC:: $method! = ' login ') && (!$_cookie[' username '])) {
$this->showmessage (' Please log in after operation! ', ' admin.php?controller=admin&method=login ');
}else{
$this->auth = isset ($_session[' username ")? $_session[' auth ']:array ();
}
}

Public Function login () {
if (!isset ($_post[' submit ')) {
VIEW::d isplay (' admin/login.html ');
}else {
$this->checklogin ();
}
}

Public Function Checklogin () {
$username = daddslashes ($_post[' username ');
$password = MD5 (daddslashes ($_post[' password '));
$auth =m (' admin ')->findone_by_username ($username);
if ((!empty ($auth)) && $auth [' Password ']== $password) {
$_session[' username ']= $username;
Setcookie (' username ', $username, Time () +3600*12);

Echo 1;
Exit
echo "";
}elseif (Empty ($auth)) {
echo "User does not exist";
Exit
$this->showmessage ("User does not exist", ' admin.php?controller=admin&method=login ');
}elseif ((!empty ($auth)) && $auth [' Password ']!= $password) {
echo "Password Error";
$this->showmessage ("Password error", ' Admin.php?controller=admin&method=login ');; /Password Error
}

}




admin.php is a portal file
Header ("content-type:text/html; Charset=utf-8 ");
URL form index.php?controller= Controller name &method= method name
Require_once (' config.php ');
Require_once (' framework/pc.php ');
Pc::run ($config);

You are using a framework, then the framework should have an AJAX pattern
Usually the framework completes the complete process, thus outputting the page HTML
But Ajax generally does not need to output the page, so you should turn on Ajax mode, so that the workflow changes

No, this is a set of simple miniature frames that I wrote myself.

I didn't write anything about Ajax at the time of the setup.


Then I introduced the Smarty template engine into the MVC view layer.

You write it, you have to make it up.
Ajax and ordinary page output different, unified processing nature is defective

If the AJAX request, then add a parameter to tell the portal program admin.php, do not load the template.

Over here
$.ajax ({
URL: ' Admin.php?controller=admin&method=login ',
...
});
Did not submit $_post[' submit '])
Admin controller inside the

Public Function Login () {if (!isset ($_post[' submit ')) {VIEW::d isplay (' admin/login.html ');} else {$this->checklogin ();}}

Method
Then execute VIEW::d isplay (' admin/login.html ');
So, the template is loaded.

It is recommended to use the Firefox Firebug or Chrome core browser developer Tools Newwork, submit, to see if there is no past submit this parameter.

or check to see if there's a value for name Form1.

Thank you for trying, and I might have to ask you.




I made it out of Firebug.

The response, and the submit.

Write a log step by step tracking look.

To ensure that Echo 1 does not have any form of text output, then the corresponding page of the PHP end symbol? > Remove

Directly put the Ajax access address and parameters in the browser execution to see it, in step-by-step debugging

Ajaxreturn

Can you say something more specific?

I have the same problem, how to solve it
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.