---
title: "Using Ajax method call"  
description: "Using Ajax method call"  
author: "Manoj Bhatt"  
published: 2014-11-17  
updated: 2014-11-17  
canonical: https://www.mindstick.com/forum/12626/using-ajax-method-call  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 1 minute  

---

# Using Ajax method call

i have this [aspx view](https://www.mindstick.com/interview/23259/differences-between-razor-and-aspx-view-engine-in-mvc) :

```
 jQuery('#addjob').click(function () {            if ($('#metier').val().length > 0) {                $('.taglist').append('<li style="line-height: 20px"><a href="" style="width:250px" >' + $('#metier').val() + '<span class="icon-remove"></span></a></li>');                $.ajax({                    type: "POST",                    url: "JobsEdition.aspx/AjouterMetier",                    data: "{'job': '" + $('#metier').val() + "'}",                    success: function (msg) {                        AjaxSucceeded(msg);                    },                    error: AjaxFailed                });                                              }            $('#metier').val('');        });
```

In the code behin i put this [method](https://www.mindstick.com/forum/166/webservice-method) :

```
 public partial class JobsEdition : System.Web.UI.Page    {      List<string> jobs = new List<string>();        [WebMethod()]        public void AjouterMetier(string job)        {            if (job != "")            {                jobs.Add(job);                Session["jobs"] = jobs;            }         }}
```

I'm [beginner](https://www.mindstick.com/forum/23159/need-beginner-project-ideas) in the use of [ajax](https://www.mindstick.com/articles/1541/check-availability-of-user-name-or-email-using-asp-dot-net-ajax-and-jquery) in [Asp.net](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder), so i had always the [session variables](https://www.mindstick.com/forum/386/retreive-data-from-bo-object-to-session-variables) Session["jobs"] null and the method AjouterMetier was [never](https://yourviews.mindstick.com/view/290/zoos-prisons-for-beings-who-have-never-committed-a-crime) reached .

What is the [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) that I commited?

How can i fix it?

## Replies

### Reply by Sumit Kesarwani

Hi Manoj, \

Since your adding items to the [session](https://www.mindstick.com/articles/12042/session-in-c-sharp):

Session["jobs"] = jobs;

You might want to initialize the variable by grabbing it from session prior. For instance:

```
public void AjouterMetier(string job){  if (job !="")  {    jobs =(List<string>)Session["jobs"] ;    if( jobs == null )      jobs = new List<string>();     jobs.Add(job);   
Session["jobs"] = jobs;  }}
```


---

Original Source: https://www.mindstick.com/forum/12626/using-ajax-method-call

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
