ThinkPHP5 ajax submits form operation instance analysis, thinkphp5ajax

Source: Internet
Author: User

ThinkPHP5 ajax submits form operation instance analysis, thinkphp5ajax

This document describes how to submit a form using thinkPHP5 ajax. We will share this with you for your reference. The details are as follows:

<! DOCTYPE html> 

In fact, there is no difference with normal ajax, mainly because jquery'sserialize()Method serialization form

I encountered some trouble in the middle, that is, I am not familiar with the thinkphp5 framework. I have been using 3.2.3 before, but the differences between the two versions are still there.

One is $ _ POST, and the other is that the original ajax url can be used to use the U method of the Framework. Instead, I looked at the Helper function under think and found that it is a url.

Below is a method that is used to return json data.

Public function test ($ mess, $ id) {if ($ mess = '000000') {return json ("ajax successful! ". $ Mess. "---". $ id) ;}else {return json ("You output other values :". $ mess. "---". $ id );}}

In addition, the common parameter submission and processing methods are as follows:

Input parameters in Form submission:

<input type="hidden" name="project_name" value="$project_name"/>

Get In Controller

$project_name=input("post.project_name");

Jump parameters in php:

$ This-> success ('Project added successfully', url ("Version/index", array ('Project _ name' => $ project_name); die;

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.