SlideShare a Scribd company logo
JQuery POST method in PHP
Many of you already know about JQuery and its utilities. For the ones who are still unaware of
the JQuery library and its usage, you can go through this article to get a brief introduction on the
matter. Of course there is always the official website for you to refer to.
The POST method in JQuery handles AJAX calls to transfer data from one file to another. This
function is similar to a POST method of that of a simple HTML form. The data passes according
to the field and variable names and is collected in a PHP file at the server end. You might declare
the POST method from a PHP file or an HTML file.
Also read my article on AJAX database update with JQuery POST
The difference lies in the fact that – for form POST methods in plain HTML, the variables are
passed with page navigation. The server side file is loaded and then the data is collected and
worked upon. However, the JQuery POST method uses an asynchronous method of sending the
data. So, there is no question of page load or navigation. The control stays on the same page.
Thus the process is faster and does not trouble the speed bandwidth.

JQuery POST method basics
The JQuery POST method is simple to call and use. There are two methods of calling the
method. Here are the two methods mentioned –
$.ajax(
type: „POST‟,
url: „save.php‟,
data: {name:name,password:password},
dataType: 'HTML',
success: function(value){
// Do something here
}
);

And the other method is –
$.post(„save.php‟,{name:name,password:password},function(value){
// Do something here.
});

As you can see, the calling of the JQuery POST method is very simple. For your understanding,
let me explain each of the section clearly.
For the first method of calling, the AJAX method is called. The method type is set to be POST.
You can set it as GET as well if you want a GET method type. Here GET or POST does not
matter as much because here the data is passed to the server in an asynchronous manner. So,
there is no chance of the data getting showed up in the URL. Next we have ‘url’. This URL is the
path to the PHP file that receives the data from here to manipulate or work upon.
The ‘data’ is the values that we want to send. Always remember, this data gets transported as
JSON and the variable name that you set here must match the name of the variable in the PHP
file that receives the respective value.
The ‘dataType’ parameter indicates the type of data that is returned back to this current file from
the server end upon successful transmission of the data to the server file. By default, this is set to
HTML. You can set it as JSON or XML. The return value will automatically change.
Suppose you have a scenario where you send a data to the server PHP file and query something
from the database. After this, instead of appending a static content to your current HTML page
you want to append a dynamic value from the server end. This is when you require JSON. I will
elaborate on this a bit later.
Finally, the ‘success’ parameter defines the function that is called when a successful sending is
done. Normally the value that comes back in the ‘dataType’ format is worked upon in this
callback success function.
Now, you can easily make out that in the second form of declaration the format is a bit different
but the parameters are same. The ‘url’ parameter comes first, then the ‘data’ and then the
callback ‘success’ function. This is actually shorthand syntax. The ‘dataType’ parameter is not
explicitly mentioned because normally developers make use of the HTML return value. If you
need JSON value, just do the following –
$.post(„save.php‟,{name:name,password:password},function(value){
// Do something here
},‟JSON‟);

Common examples of JQuery POST method
The POST method comes very handy when you require server side interference. Otherwise, for
any static data you would never require this method. One of the most used techniques is
validating new usernames or emails with the existing user base. Several websites implement this.
The idea is as soon as the user starts typing in the username of their choice, the server is passed
the current value and a message is appended instantly to notify whether this username is
available or not. I have already discussed and given an example of this working in this article.
Check it out.
Another good example of JQuery POST method usage would be using a JSON return type. This
is when you want the user to see a dynamic value (a value from the database according to the
current user entry) when a certain event is performed.
For example, you enter the name of a student and you get to see which subjects he or she has
opted for – instantly! Yes that is only possible with a JQuery POST method with JSON return
type. The value passed back will be in the form of a JSON array, you need to access the values
and get them appended to the HTML. This is not possible for you to achieve in a simple .html
file unless you add a JQuery POST method. Here’s a demo code // The JQuery code in the HTML file
$(„#textbox‟).keydown(function(){
$.post(„subjects.php‟, {name:name}, function(value){
for(var i=0;i<value.length;i++){
$(„#subjects ul‟).append(„<ul style="text-align: justify;">
<li>‟+value[i]+‟</li></ul>‟); } }, „json‟);
});
// The PHP code (assuming that DB is connected)
$name = $_POST[„name‟];
$query = “SELECT subjects FROM students WHERE name=‟”.$name.”‟”;
$result = mysql_query($query)
or die();
$sub = mysql_fetch_assoc($result);
echo json_encode($sub);

Common errors in JQuery POST method
When you try using this method always keep in mind the following points. These are some of the
most commonly arising errors that I have faced. So, I thought of letting you guys know so that
you do not face same trouble.
- Make sure that while sending the ‘data’ in the JQuery POST method, the variable name that
comes on the left of each JSON array element composition is the name that the program expects
to be as the PHP file receiving variable name. Let’s make it simpler. Check the following code –
// if this your POST method „data‟
{a:name,password:b}

Then, the PHP file expects that when you receive the values as $_POST[], the variable that
accepts the value will have the same name as the left component. The right component is the
JavaScript variable. In this case, ‘name’ and ‘b’ are the JavaScript variables. So in the PHP file
we write –
$a = $_POST[„a‟]; $password = $_POST[„password‟];

- Always make sure the URL to the PHP file is correct.
- If in case you have a success function and it’s not working; try removing the statements inside
the function and make an alert. If the alert happens then there is something wrong in the
statements inside your callback function.
If the alert does not happen, then the program control is getting stuck in the PHP file. Check that
file. If it’s an issue with the PHP file, check the queries and the return values. They often create a
tantrum.
That’s all about this method. Try and let me know what you did.
Ad

More Related Content

What's hot (20)

JSON
JSONJSON
JSON
Zara Tariq
 
JSON
JSONJSON
JSON
Ibrahim AlIbrahim
 
Json
JsonJson
Json
baabtra.com - No. 1 supplier of quality freshers
 
Json Tutorial
Json TutorialJson Tutorial
Json Tutorial
Napendra Singh
 
JSON and XML
JSON and XMLJSON and XML
JSON and XML
People Strategists
 
Json
JsonJson
Json
krishnapriya Tadepalli
 
JSON and REST
JSON and RESTJSON and REST
JSON and REST
Robert MacLean
 
Json
JsonJson
Json
Sabarinath Gnanasekar
 
Json
JsonJson
Json
Steve Fort
 
Php forms
Php formsPhp forms
Php forms
Anne Lee
 
java script json
java script jsonjava script json
java script json
chauhankapil
 
What is JSON? Why use JSON? JSON Types? JSON Helpful Tools?
What is JSON? Why use JSON? JSON Types? JSON Helpful Tools?What is JSON? Why use JSON? JSON Types? JSON Helpful Tools?
What is JSON? Why use JSON? JSON Types? JSON Helpful Tools?
codeandyou forums
 
Xml
XmlXml
Xml
Yoga Raja
 
JSON - Quick Overview
JSON - Quick OverviewJSON - Quick Overview
JSON - Quick Overview
Signure Technologies
 
Pollock
PollockPollock
Pollock
tomelf2007
 
MuleSoft DataWeave data transformation language
MuleSoft DataWeave data transformation languageMuleSoft DataWeave data transformation language
MuleSoft DataWeave data transformation language
fganora
 
Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04
Spy Seat
 
Php, mysq lpart4(processing html form)
Php, mysq lpart4(processing html form)Php, mysq lpart4(processing html form)
Php, mysq lpart4(processing html form)
Subhasis Nayak
 
Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5
Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5
Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5
Salvatore Iaconesi
 
PHP Tutorials
PHP TutorialsPHP Tutorials
PHP Tutorials
Yuriy Krapivko
 

Viewers also liked (8)

Seo presentation dm10
Seo presentation   dm10Seo presentation   dm10
Seo presentation dm10
Rune Risom
 
Kom godt i gang med: At få en god plads på Google
Kom godt i gang med: At få en god plads på GoogleKom godt i gang med: At få en god plads på Google
Kom godt i gang med: At få en god plads på Google
Rune Risom
 
Badly Drawn Boy - Samsonic
Badly Drawn Boy - SamsonicBadly Drawn Boy - Samsonic
Badly Drawn Boy - Samsonic
Fenneke van der Aa
 
Spring-Summer 2011 (part 1)
Spring-Summer 2011 (part 1)Spring-Summer 2011 (part 1)
Spring-Summer 2011 (part 1)
Babyholiday Btq
 
Node.js: perche' tutto questo hype?
Node.js: perche' tutto questo hype?Node.js: perche' tutto questo hype?
Node.js: perche' tutto questo hype?
Giancarlo Valente
 
What's so special about node.js
What's so special about node.jsWhat's so special about node.js
What's so special about node.js
Giancarlo Valente
 
Iffis14 datavisualisering
Iffis14 datavisualiseringIffis14 datavisualisering
Iffis14 datavisualisering
Chalmers Library
 
Mobil app
Mobil appMobil app
Mobil app
Chalmers Library
 
Seo presentation dm10
Seo presentation   dm10Seo presentation   dm10
Seo presentation dm10
Rune Risom
 
Kom godt i gang med: At få en god plads på Google
Kom godt i gang med: At få en god plads på GoogleKom godt i gang med: At få en god plads på Google
Kom godt i gang med: At få en god plads på Google
Rune Risom
 
Spring-Summer 2011 (part 1)
Spring-Summer 2011 (part 1)Spring-Summer 2011 (part 1)
Spring-Summer 2011 (part 1)
Babyholiday Btq
 
Node.js: perche' tutto questo hype?
Node.js: perche' tutto questo hype?Node.js: perche' tutto questo hype?
Node.js: perche' tutto questo hype?
Giancarlo Valente
 
What's so special about node.js
What's so special about node.jsWhat's so special about node.js
What's so special about node.js
Giancarlo Valente
 
Ad

Similar to J query post method in php (20)

forms.pptx
forms.pptxforms.pptx
forms.pptx
asmabagersh
 
Working with data.pptx
Working with data.pptxWorking with data.pptx
Working with data.pptx
SherinRappai
 
How to insert json data into my sql using php
How to insert json data into my sql using phpHow to insert json data into my sql using php
How to insert json data into my sql using php
Trà Minh
 
GET and POST in PHP
GET and POST in PHPGET and POST in PHP
GET and POST in PHP
Vineet Kumar Saini
 
Php forms and validations by naveen kumar veligeti
Php forms and validations by naveen kumar veligetiPhp forms and validations by naveen kumar veligeti
Php forms and validations by naveen kumar veligeti
Naveen Kumar Veligeti
 
Ajax
AjaxAjax
Ajax
husnara mohammad
 
Class 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingClass 6 - PHP Web Programming
Class 6 - PHP Web Programming
Ahmed Swilam
 
Unit-5.pptx
Unit-5.pptxUnit-5.pptx
Unit-5.pptx
itzkuu01
 
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldkskUnit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
cpbloger553
 
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldkskUnit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
cpbloger553
 
PHP-Part4
PHP-Part4PHP-Part4
PHP-Part4
Ahmed Saihood
 
Implementing Ajax In ColdFusion 7
Implementing Ajax In ColdFusion 7Implementing Ajax In ColdFusion 7
Implementing Ajax In ColdFusion 7
Pranav Prakash
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3
tutorialsruby
 
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
tutorialsruby
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3
tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
tutorialsruby
 
Lecture7 form processing by okello erick
Lecture7 form processing by okello erickLecture7 form processing by okello erick
Lecture7 form processing by okello erick
okelloerick
 
Web app development_php_07
Web app development_php_07Web app development_php_07
Web app development_php_07
Hassen Poreya
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
Adnan Sohail
 
Core Java tutorial at Unit Nexus
Core Java tutorial at Unit NexusCore Java tutorial at Unit Nexus
Core Java tutorial at Unit Nexus
Unit Nexus Pvt. Ltd.
 
Working with data.pptx
Working with data.pptxWorking with data.pptx
Working with data.pptx
SherinRappai
 
How to insert json data into my sql using php
How to insert json data into my sql using phpHow to insert json data into my sql using php
How to insert json data into my sql using php
Trà Minh
 
Php forms and validations by naveen kumar veligeti
Php forms and validations by naveen kumar veligetiPhp forms and validations by naveen kumar veligeti
Php forms and validations by naveen kumar veligeti
Naveen Kumar Veligeti
 
Class 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingClass 6 - PHP Web Programming
Class 6 - PHP Web Programming
Ahmed Swilam
 
Unit-5.pptx
Unit-5.pptxUnit-5.pptx
Unit-5.pptx
itzkuu01
 
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldkskUnit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
cpbloger553
 
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldkskUnit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
cpbloger553
 
Implementing Ajax In ColdFusion 7
Implementing Ajax In ColdFusion 7Implementing Ajax In ColdFusion 7
Implementing Ajax In ColdFusion 7
Pranav Prakash
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3
tutorialsruby
 
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
tutorialsruby
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3
tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
tutorialsruby
 
Lecture7 form processing by okello erick
Lecture7 form processing by okello erickLecture7 form processing by okello erick
Lecture7 form processing by okello erick
okelloerick
 
Web app development_php_07
Web app development_php_07Web app development_php_07
Web app development_php_07
Hassen Poreya
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
Adnan Sohail
 
Ad

Recently uploaded (20)

The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
SOFTTECHHUB
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
An Overview of Salesforce Health Cloud & How is it Transforming Patient Care
An Overview of Salesforce Health Cloud & How is it Transforming Patient CareAn Overview of Salesforce Health Cloud & How is it Transforming Patient Care
An Overview of Salesforce Health Cloud & How is it Transforming Patient Care
Cyntexa
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à GenèveUiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPathCommunity
 
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
CSUC - Consorci de Serveis Universitaris de Catalunya
 
Top-AI-Based-Tools-for-Game-Developers (1).pptx
Top-AI-Based-Tools-for-Game-Developers (1).pptxTop-AI-Based-Tools-for-Game-Developers (1).pptx
Top-AI-Based-Tools-for-Game-Developers (1).pptx
BR Softech
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 
IT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information TechnologyIT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information Technology
SHEHABALYAMANI
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
Artificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptxArtificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptx
03ANMOLCHAURASIYA
 
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Christian Folini
 
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
SOFTTECHHUB
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
An Overview of Salesforce Health Cloud & How is it Transforming Patient Care
An Overview of Salesforce Health Cloud & How is it Transforming Patient CareAn Overview of Salesforce Health Cloud & How is it Transforming Patient Care
An Overview of Salesforce Health Cloud & How is it Transforming Patient Care
Cyntexa
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à GenèveUiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPathCommunity
 
Top-AI-Based-Tools-for-Game-Developers (1).pptx
Top-AI-Based-Tools-for-Game-Developers (1).pptxTop-AI-Based-Tools-for-Game-Developers (1).pptx
Top-AI-Based-Tools-for-Game-Developers (1).pptx
BR Softech
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 
IT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information TechnologyIT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information Technology
SHEHABALYAMANI
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
Artificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptxArtificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptx
03ANMOLCHAURASIYA
 
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Christian Folini
 

J query post method in php

  • 1. JQuery POST method in PHP Many of you already know about JQuery and its utilities. For the ones who are still unaware of the JQuery library and its usage, you can go through this article to get a brief introduction on the matter. Of course there is always the official website for you to refer to. The POST method in JQuery handles AJAX calls to transfer data from one file to another. This function is similar to a POST method of that of a simple HTML form. The data passes according to the field and variable names and is collected in a PHP file at the server end. You might declare the POST method from a PHP file or an HTML file. Also read my article on AJAX database update with JQuery POST The difference lies in the fact that – for form POST methods in plain HTML, the variables are passed with page navigation. The server side file is loaded and then the data is collected and worked upon. However, the JQuery POST method uses an asynchronous method of sending the data. So, there is no question of page load or navigation. The control stays on the same page. Thus the process is faster and does not trouble the speed bandwidth. JQuery POST method basics The JQuery POST method is simple to call and use. There are two methods of calling the method. Here are the two methods mentioned – $.ajax( type: „POST‟, url: „save.php‟, data: {name:name,password:password}, dataType: 'HTML', success: function(value){ // Do something here } ); And the other method is – $.post(„save.php‟,{name:name,password:password},function(value){ // Do something here. }); As you can see, the calling of the JQuery POST method is very simple. For your understanding, let me explain each of the section clearly. For the first method of calling, the AJAX method is called. The method type is set to be POST. You can set it as GET as well if you want a GET method type. Here GET or POST does not matter as much because here the data is passed to the server in an asynchronous manner. So,
  • 2. there is no chance of the data getting showed up in the URL. Next we have ‘url’. This URL is the path to the PHP file that receives the data from here to manipulate or work upon. The ‘data’ is the values that we want to send. Always remember, this data gets transported as JSON and the variable name that you set here must match the name of the variable in the PHP file that receives the respective value. The ‘dataType’ parameter indicates the type of data that is returned back to this current file from the server end upon successful transmission of the data to the server file. By default, this is set to HTML. You can set it as JSON or XML. The return value will automatically change. Suppose you have a scenario where you send a data to the server PHP file and query something from the database. After this, instead of appending a static content to your current HTML page you want to append a dynamic value from the server end. This is when you require JSON. I will elaborate on this a bit later. Finally, the ‘success’ parameter defines the function that is called when a successful sending is done. Normally the value that comes back in the ‘dataType’ format is worked upon in this callback success function. Now, you can easily make out that in the second form of declaration the format is a bit different but the parameters are same. The ‘url’ parameter comes first, then the ‘data’ and then the callback ‘success’ function. This is actually shorthand syntax. The ‘dataType’ parameter is not explicitly mentioned because normally developers make use of the HTML return value. If you need JSON value, just do the following – $.post(„save.php‟,{name:name,password:password},function(value){ // Do something here },‟JSON‟); Common examples of JQuery POST method The POST method comes very handy when you require server side interference. Otherwise, for any static data you would never require this method. One of the most used techniques is validating new usernames or emails with the existing user base. Several websites implement this. The idea is as soon as the user starts typing in the username of their choice, the server is passed the current value and a message is appended instantly to notify whether this username is available or not. I have already discussed and given an example of this working in this article. Check it out. Another good example of JQuery POST method usage would be using a JSON return type. This is when you want the user to see a dynamic value (a value from the database according to the current user entry) when a certain event is performed. For example, you enter the name of a student and you get to see which subjects he or she has opted for – instantly! Yes that is only possible with a JQuery POST method with JSON return
  • 3. type. The value passed back will be in the form of a JSON array, you need to access the values and get them appended to the HTML. This is not possible for you to achieve in a simple .html file unless you add a JQuery POST method. Here’s a demo code // The JQuery code in the HTML file $(„#textbox‟).keydown(function(){ $.post(„subjects.php‟, {name:name}, function(value){ for(var i=0;i&lt;value.length;i++){ $(„#subjects ul‟).append(„<ul style="text-align: justify;"> <li>‟+value[i]+‟</li></ul>‟); } }, „json‟); }); // The PHP code (assuming that DB is connected) $name = $_POST[„name‟]; $query = “SELECT subjects FROM students WHERE name=‟”.$name.”‟”; $result = mysql_query($query) or die(); $sub = mysql_fetch_assoc($result); echo json_encode($sub); Common errors in JQuery POST method When you try using this method always keep in mind the following points. These are some of the most commonly arising errors that I have faced. So, I thought of letting you guys know so that you do not face same trouble. - Make sure that while sending the ‘data’ in the JQuery POST method, the variable name that comes on the left of each JSON array element composition is the name that the program expects to be as the PHP file receiving variable name. Let’s make it simpler. Check the following code – // if this your POST method „data‟ {a:name,password:b} Then, the PHP file expects that when you receive the values as $_POST[], the variable that accepts the value will have the same name as the left component. The right component is the JavaScript variable. In this case, ‘name’ and ‘b’ are the JavaScript variables. So in the PHP file we write – $a = $_POST[„a‟]; $password = $_POST[„password‟]; - Always make sure the URL to the PHP file is correct. - If in case you have a success function and it’s not working; try removing the statements inside the function and make an alert. If the alert happens then there is something wrong in the statements inside your callback function. If the alert does not happen, then the program control is getting stuck in the PHP file. Check that file. If it’s an issue with the PHP file, check the queries and the return values. They often create a tantrum.
  • 4. That’s all about this method. Try and let me know what you did.
  翻译: