/ / Plugin do temporizador JQuery no botão Página do ASP.NET MVC click - jquery, asp.net-mvc, asp.net-mvc-2

Plugin do timer JQuery no botão ASP.NET MVC Page clique em - jquery, asp.net-mvc, asp.net-mvc-2

Eu tenho uma página ASP.NET MVC com um botão chamado "Start Live Meeting".

Quando o usuário clica nesse botão, ele chama um método controlador chamado "StartLiveMeeting" que retorna uma string.

Se o controlador retornar uma string vazia, eu quero que o Timer chame o método Controller até que ele retorne a string. Eu estou usando o plugin jquery.timer.js ( http://plugins.jquery.com/files/jquery.timers-1.2.js.txt )

No botão, o método do controlador está sendo chamado. Mas o Timer não está iniciando. Eu especifiquei 5sec para chamar o método do controlador.

Eu aprecio suas respostas.

Código na página ASPX:

//When "Start Meeting" button is clicked, if it doesn’t return empty string, Display that text and Stop Timer. Else call the Timer in every 5 sec and call the StartLiveMeeting Controller method.

$("#btnStartMeeting").click(function() {
var lM = loadLiveMeeting();
if (lM == "") {
$("#btnStartMeeting").oneTime("5s", function() {
});
} else {
$("#btnStartMeeting").stopTime("hide");
}
return false;
});
function loadLiveMeeting() {
$("#divConnectToLive").load("<%= Url.Action("StartLiveMeeting") %>", {}, function(responseText, status) {
return responseText;
});
}

<asp:Content ID="Content2" ContentPlaceHolderID="cphMain" runat="server">

<div id="divStartMeetingButton"><input id="btnStartMeeting" type="submit" value="Start Meeting" />
</div>
<div id = "divConnectToLive">
<div id="loading" style="visibility:hidden">
<img src="/images/../../img/MedInfo/ajax_Connecting.gif" alt="Loading..." />
</div>
</div>

Método do Controlador:

[HttpPost]
public string StartLiveMeeting()
{
int intCM_Id = ((CustomerMaster)Session["CurrentUser"]).CM_Id ;
var activeMeetingReq = (from m in miEntity.MeetingRequest
where m.CustomerMaster.CM_Id == intCM_Id
&& m.Active == true
select m);

if (activeMeetingReq.Count() > 0)
{
MeetingRequest meetingReq = activeMeetingReq.First();
return "<a href="" + meetingReq.URI + "">" + "Connect to Live Meeting</a>";
} else {
return "";
}
}

Respostas:

1 para resposta № 1

o load() O método é assíncrono, portanto, você precisará torná-lo síncrono ou colocar sua lógica de resposta no retorno de chamada.

$("#btnStartMeeting").click(function() {
loadLiveMeeting();
return false;
});
function loadLiveMeeting() {
$("#divConnectToLive").load("<%= Url.Action("StartLiveMeeting") %>", {}, function(responseText, status) {
if (responseText == "") {
$("#btnStartMeeting").oneTime("5s", function() {
// call load meeting again
});
} else {
$("#btnStartMeeting").stopTime("hide");
}
});
}