PHP and Ajax

PHP and Ajax
December 16, 2016 Comments Off on PHP and Ajax Uncategorized Vikram Patil

PHP and Ajax are combined by webmasters to make Web applications. Ajax allows you to create an interface that runs on a browser with JavaScript. Normal web applications transmit information to and from the sever using synchronous requests.
This means you fill out a form press submit button and get directed to a new page with new information from the server. With AJAX when you press submit button JavaScript will make a request to the server, interpret the results and update the current screen. In this work of ajax the user would never know that anything was even transmitted to the server.

How the Ajax call works:
url – The external URL to which we are sending the request. In this case we are organized all Ajax PHP scripts into a folder/file.
type – Type defines the request method, POST or GET.
data – What content are we passing to the PHP file? It can be JSON object, string or array.
datatype – Which type of data expected back from the server.
async – By default, all requests are send asynchronously. Set it false to make asynchronous.
username – Username to be used with XMLHttpRequest in response to an HTTP access authentication request.
password – Password to used with XMLHttpRequest in response to an HTTP access authentication request.
beforeSend – Callback function to be executed before Ajax request is send.
complete – A callback function to be executed when request finishes.
accept – The content type sent in the request header that tells the server what kind of response it will accept in return
global – Boolean indicating wether to trigger a global ajax request handler not. Default is true.
headers – Object of Additional key header key/value pair to send along with request.
isLocal – Set this true if you want to recognize the current envoirnment as local.
mimeType – String containing a mime type to override the XMLHttpRequest mime type.
contentType – Containing a type of content when sending content to the server. Default is “application/x-www-form-urlencoded; charset=UTF-8”.
processData – Indicating whether data assigned to data option will be converted to a query string. Default is true.
statusCode – JSON object containing numeric HTTP codes and functions to be called when the response has the corresponding code.
success – If the Ajax request runs successfully then we either call a separate function or write the callback inline. Usually write the function within Ajax because it’s often much easier.
error – Ajax request fails, or gets an error in the response, this alternative function is triggered. Usually helpful when debugging issues between JS and PHP.
timeout – Number value in milliseconds specifies a timeout for the request.

Example –
PHP and Ajax 1
PHP and Ajax 2

About The Author