logo

An example of basic ajax with jquery and error handling

ajax

Ajax stands for Asynchronous JavaScript and XML, means using JavaScript or Jquery we can send request to server without page reload.
we can perform ajax request using JavaScript as well as Jquery, As JQuery requires less code so I always prefer Jquery over JavaScript. in this tutorial I will do it with JQuery.

lets take an example, we have 2 dropdowns 1st one is country with id=”drpCountries” and 2nd one is city with id=”drpCities”, we populate countries using php while want to fetch cities from database when we change the country at runtime.

our HTML will look like the following snippet

for above script our php code will look like something below

You can customize it according to your requirements, I kept it more generic and simple for beginners to understand easily. comment your issues and problems and I encourage you also to reply i you can help someone else.

Comments

    Write a Reply or Comment

    Your email address will not be published. Required fields are marked *