title: How to make ajax call in sharepoint 2013
body: <p>I am writing a custom web part in sharepoint 2013. I need to make a ajax call. How I am trying
  ......</p>
  
  <p>In my <code>CafeteriaWebPart.ascx</code>, I wrote </p>
  
  <pre><code>&lt;%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %&gt;
  &lt;%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %&gt; 
  &lt;%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %&gt; 
  &lt;%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %&gt;
  &lt;%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %&gt;
  &lt;%@ Import Namespace="Microsoft.SharePoint" %&gt; 
  &lt;%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %&gt;
  &lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CafeteriaWebPart.ascx.cs" Inherits="RobiCafeteria.CafeteriaWebPart.CafeteriaWebPart" %&gt;
  
  &lt;div&gt;
      &lt;script src="http://code.jquery.com/jquery-1.10.1.min.js"&gt;&lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
      $(document).ready(
  
          function () {
              alert('Yes');
              $.ajax({
                  type: "POST",
                  url: "CafeteriaWebPart.ascx.cs/GetCafeteriaList",
                  contentType: "application/json; charset=utf-8",
                  data: {},
                  dataType: "json",
                  success: function (data) {
                      alert(data);
                  }
              });
          }
          );
  &lt;/script&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And In my CafeteriaWebPart.ascx.cs, I wrote</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Linq;
  using System.Web.UI.WebControls.WebParts;
  using System.Web.Services;
  using Microsoft.SharePoint;
  
  
  
  namespace RobiCafeteria.CafeteriaWebPart
  {
      [ToolboxItemAttribute(false)]
      public partial class CafeteriaWebPart : WebPart
      {
          // Uncomment the following SecurityPermission attribute only when doing Performance Profiling on a farm solution
          // using the Instrumentation method, and then remove the SecurityPermission attribute when the code is ready
          // for production. Because the SecurityPermission attribute bypasses the security check for callers of
          // your constructor, it's not recommended for production purposes.
          // [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Assert, UnmanagedCode = true)]
          public CafeteriaWebPart()
          {
          }
  
          protected override void OnInit(EventArgs e)
          {
              base.OnInit(e);
              InitializeControl();
          }
  
          protected void Page_Load(object sender, EventArgs e)
          {
  
          }
  
          [WebMethod]
          public List&lt;CafeteriaModel&gt; GetCafeteriaList()
          {
              var spCafeteriaList = SPContext.Current.Web.Lists["Cafeteria"];
  
              return (from SPItem item in spCafeteriaList.Items
                      select new CafeteriaModel
                                 {
                                     DayName = item["Day Name"].ToString(), MenuItem = item["Menu Item"].ToString()
                                 }).ToList();
          }
  
      }
  
      public class CafeteriaModel
      {
          public string DayName { get; set; }
          public string MenuItem { get; set; }
      }
  }
  </code></pre>
  
  <p>I am getting following error</p>
  
  <pre><code>POST http://srv-sptest:31618/SitePages/CafeteriaWebPart.ascx.cs/GetCafeteriaList 404 (NOT FOUND) 
  </code></pre>