DEV Community

aakas
aakas

Posted on • Edited on

Using AJAX for first time.

I had a task assigned to me in a internship. The task was to update the data of the details of applicant when changing the value of the "roll number" of the applicant.

I had never used AJAX before. So, it was new thing for me. At, first I thought it was easy. But, when I started to do it, i couldn't just make it right. I search on google, "how to use a ajax". Many results occured but, I was still not making any progress.

After sometime, I came to realize that I was rushing things. I was focused on result than the process, so I was not making any progress.

So, after realizing that, I focused on the process. I started to learn what actually is ajax, how to use it, what it is used for.

Ajax is use to update the web pages asynchronously by exchanging data with a web server behind the scenes. And it is used as

 $.ajax({
         url: "any url path/",
         type: "POST",
         data:{
               "key":"value",
               "roll": $('#roll').val(),
               "csrfmiddlewaretoken" : "{{csrf_token}}"  // since i am using a jinja template
              }, 
         success: function(response){
               // perform actions here;
              },
          error: function(){
               // perform actions here;
            }
        }
);
Enter fullscreen mode Exit fullscreen mode

The CSRF Token is required while making a POST request.
After learning these things, I tried and tried. There were lot of errors, warnings but i solved them one by one. And finally, the code worked and the result was visible. It felt good to see finally code worked after so many hours of working on it.

Top comments (0)