I have this code:
function EnableiPad(event) {
var id = $(event.currentTarget).attr("data-id");
var status = $(event.currentTarget).attr("data-status");
$.post("/Ipad/ChangeStatus", { id: id, enable: status }, onAjaxSuccess);
};
function onAjaxSuccess(data) {
var status = $(".button-enable").attr("data-status");
if (status == 'true')
{
$('#statusImg').attr("src", '/Content/img/disable.png');
}
else
{
$('#statusImg').attr("src", '/Content/img/enable.png');
}
}
But it doesn't change image - $('#statusImg').attr("src", '/Content/img/disable.png');
Update
Here is my images:
@if (iPad.Enabled)
{
<button class="button-enable" data-original-title="Show timetable" data-id="@iPad.Id" data-status="false" class="btn btn-mini" style="border: 0; background: transparent; box-shadow: none; padding: 0;">
<img id="status" width="24" height="24" alt="Delete doctor" src="/Content/img/enable.png" />
</button>
}
else
{
<button id="statusDisable" class="button-enable" data-original-title="Show timetable" data-id="@iPad.Id" data-status="true" class="btn btn-mini" style="border: 0; background: transparent; box-shadow: none; padding: 0;">
<img id="status" width="24" height="24" alt="Delete doctor" src="/Content/img/disable.png" />
</button>
}
I have this code:
function EnableiPad(event) {
var id = $(event.currentTarget).attr("data-id");
var status = $(event.currentTarget).attr("data-status");
$.post("/Ipad/ChangeStatus", { id: id, enable: status }, onAjaxSuccess);
};
function onAjaxSuccess(data) {
var status = $(".button-enable").attr("data-status");
if (status == 'true')
{
$('#statusImg').attr("src", '/Content/img/disable.png');
}
else
{
$('#statusImg').attr("src", '/Content/img/enable.png');
}
}
But it doesn't change image - $('#statusImg').attr("src", '/Content/img/disable.png');
Update
Here is my images:
@if (iPad.Enabled)
{
<button class="button-enable" data-original-title="Show timetable" data-id="@iPad.Id" data-status="false" class="btn btn-mini" style="border: 0; background: transparent; box-shadow: none; padding: 0;">
<img id="status" width="24" height="24" alt="Delete doctor" src="/Content/img/enable.png" />
</button>
}
else
{
<button id="statusDisable" class="button-enable" data-original-title="Show timetable" data-id="@iPad.Id" data-status="true" class="btn btn-mini" style="border: 0; background: transparent; box-shadow: none; padding: 0;">
<img id="status" width="24" height="24" alt="Delete doctor" src="/Content/img/disable.png" />
</button>
}
Share
Improve this question
edited Aug 10, 2012 at 7:52
Tim B James
20.4k4 gold badges76 silver badges106 bronze badges
asked Aug 10, 2012 at 7:42
revolutionkpirevolutionkpi
2,68211 gold badges49 silver badges87 bronze badges
5
- you missed the last bracket. Is the actual code like that or this is just a typo? – davids Commented Aug 10, 2012 at 7:45
-
1
This calls for basic debugging first. At which point does it fail - is
EnableiPad()
ever called? Is the Ajax request ever fired? Does the success callback ever e back? Are there any error messages in the console? – Pekka Commented Aug 10, 2012 at 7:45 - It seems valid. Probably the problem is in something subtle. – Lyubomir Vasilev Commented Aug 10, 2012 at 7:46
-
Any errors? Why are you handling the image change in the callback function when you don't seem to use the
data
from the callback? why not just do it prior to thepost
event? – Tim B James Commented Aug 10, 2012 at 7:47 -
$('#statusImg').attr("src", '/Content/img/disable.png');
should work fine if selector is ok. Try to debug app more. – Michael Commented Aug 10, 2012 at 7:47
1 Answer
Reset to default 7id of your img tag is status, so it should be:
$('#status').attr("src", '/Content/img/disable.png');