Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax function doesn't seem working
    primarykey
    data
    text
    <p>I'm developing an online application of tennis club management... (MVC 3, Entity Framework Code first,...) </p> <p>I've an Interface that allows the user to consult the <strong>available tennis court</strong> :</p> <p><img src="https://i.stack.imgur.com/lmqeo.jpg" alt="enter image description here"></p> <p><strong>In my "AvailableCourtController", I've a function which return the tennis courts :</strong></p> <pre><code> [HttpPost] public JsonResult GetTennisCourt(DateTime date) { var reservations = db.Reservations.Include(c =&gt; c.Customer); foreach (var reservation in reservations) { //Verify that a court is available or not if (reservation.Date ==date) { if (date.Hour &gt; reservation.FinishTime.Hour || date.Hour &lt; reservation.StartTime.Hour) { var id = reservation.TennisCourtID; TennisCourt tennisCourt = (TennisCourt) db.TennisCourts.Where(t =&gt; t.ID == id); tennisCourt.Available = true; db.Entry(tennisCourt).State = EntityState.Modified; db.SaveChanges(); } else { var id = reservation.TennisCourtID; TennisCourt tennisCourt = (TennisCourt) db.TennisCourts.Where(s =&gt; s.ID == id); tennisCourt.Available = false; db.Entry(tennisCourt).State = EntityState.Modified; db.SaveChanges(); break; } } } var courts = from c in db.TennisCourts select c; courts = courts.OrderBy(c =&gt; c.ID); return Json(courts, JsonRequestBehavior.AllowGet ); } </code></pre> <p><strong>So, I would like to change the color of my label if the tennis court is busy or free... For that I use "Ajax":</strong> </p> <p><em>"View"</em> <em>(What I've tried to make)</em></p> <pre><code>&lt;input id="datePicker" type= "text" onchange="loadCourts"/&gt; &lt;script type="text/javascript"&gt; $('#datePicker').datetimepicker(); &lt;/script&gt; &lt;script type="text/javascript"&gt; function loadCourts() { var myDate = $('#datePicker').value(); $.ajax({ url: ("/AvailableCourt/GetTennisCourt?date=myDate "), success: function (data) { alert('test'); //change label's color } }); } &lt;/script&gt; </code></pre> <p>I never get the message "test"... So I have make something wrong with my Ajax function or my controller's method... My goal is to get the tennis court, check if they're free or not and change color in red if busy, and in green if free...</p> <p><strong>Can you help me to find what I'm doing wrong please?</strong> Sorry :( But I'm a beginner with Ajax...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload