Example of .success() and .error() method in $.post() or $.get()


In this code i include .success() method that notify user if the $.post() operation is success and .error() method to notify if some error take place like if the php file is not valid or faild to find out the php file.
You can test it by changing the name of the php file..

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
<script type=”text/javascript” src=”jquery.js”></script>
<script type=”text/javascript”>


var val = $(‘#text’).val();
$.post(‘sample.php’,{value: val}).success(function(){



alert(‘an error occured’);




<input type=”text” id=”text” /><input type=”button” value=”Send” id=”button”/><br />

<span id=”spa”></span>

By kfelahi Posted in JQuery

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s