Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Webmethod中重定向_Javascript_C#_Asp.net_Webmethod_Response.redirect - Fatal编程技术网

Javascript 在Webmethod中重定向

Javascript 在Webmethod中重定向,javascript,c#,asp.net,webmethod,response.redirect,Javascript,C#,Asp.net,Webmethod,Response.redirect,我试图在call webmethod中使用response.redirect命令,但该命令不起作用,请参阅我的代码: HTML: C: 我不能使用命令重定向页面,我已经尝试了几种方法,例如通过字符串返回链接等 此代码的工作原理如下:我单击链接,它调用javascript函数,此函数获取页面某些组件的一些信息,并通过webmethod将其发送到服务器端。webmethod无法使用Response.redirect将网站重定向到其他地址。它将向调用者发送一个XML响应。尝试从webmethod发送所

我试图在call webmethod中使用response.redirect命令,但该命令不起作用,请参阅我的代码:

HTML:

C:

我不能使用命令重定向页面,我已经尝试了几种方法,例如通过字符串返回链接等


此代码的工作原理如下:我单击链接,它调用javascript函数,此函数获取页面某些组件的一些信息,并通过webmethod将其发送到服务器端。

webmethod无法使用Response.redirect将网站重定向到其他地址。它将向调用者发送一个XML响应。尝试从webmethod发送所需信息,然后使用它重定向页面。

如果调用异步方法,或者根据网站上的值重定向,则可以使用此行重定向网站:

document.location.href = url;
不要在服务器代码上使用重定向,而是直接从[WebMethod]-NextAula发送链接,并在js端使用它


eadVerAula.aspx?codaula=+paula.eadcodaula+&t=+paula.eadcodmidia,返回此值。

是否尝试从JS调用web服务?Web服务没有Response.Redirect。请尝试将您要重定向到的地址作为响应的一部分返回,而不是让WebMethod重定向页面,然后让客户端读取响应以获取要重定向到的URL,然后让客户端访问新的URL。在代码PageMethods中更改此行。NextAulaelem,npag,getParameterByName'codaula';`to var strRedirect=PageMethods.NextAulaelem、npag、getParameterByName'codaula';然后在WebMethod中,将return从return更改为返回您分配给本地变量的实际字符串值,以便分配link=eadVerAula.aspx?codaula=+paula.eadcodaula+&t=+paula.eadcodmidia;然后返回应该是return linkvar strRedirect=PageMethods.NextAula elem,NPAG,getParameterByName'codaula';return unefinedbut在客户端JS中不希望webmethod完成,JS运行webmethod并继续下一行在JS中使用此命令:我需要服务器检查数据库中的信息,但不触发回发的唯一方法是使用webmethod,正如我对webmethod所做的那样,返回clientside?的数据@ISFO,这不是真的。WebMethod有几种不再受支持的替代方法。是目前最容易使用的工具之一。
 function proximaAula() {
    var tipo = getParameterByName('t');
    if (tipo == "1") {
        //PageMethods.MyMethod(projekktor('player_a').getPosition(), projekktor('player_a').getDuration(), getParameterByName('codaula'));
        PageMethods.NextAula(projekktor('player_a').getPosition(), projekktor('player_a').getDuration(), getParameterByName('codaula'));
    }
    //alert(tipo);
    if (tipo == "3") {
        var iframe = document.getElementById('viewer');
        var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
        var pag;
        var npag;
        if (iframeDocument) {
            elem = iframeDocument.getElementById('pageNumber').value;
            npag = iframeDocument.getElementById('numPages').innerHTML;
            npag = npag.substring(3, npag.length);
        }
        //return "asasdas"; // 
        //alert(elem + " - " + npag);
        PageMethods.NextAula(elem,npag,getParameterByName('codaula'));
    }
    if (tipo == "4") {
        PageMethods.NextAula("-1","-1",getParameterByName('codaula'));
    }
}
[WebMethod]
    public static string NextAula(string tempo, string tempomax, string codaula)
    {
        escolawebEntities DB = new escolawebEntities();
        string link = "";
        int icodaula = int.Parse(codaula);

        eadaulaaluno eaula = (from x in DB.eadaulaaluno where x.codeadaula == icodaula select x).FirstOrDefault();

        tempo = tempo.Substring(0, tempo.IndexOf('.'));
        tempomax = tempomax.Substring(0, tempomax.IndexOf('.'));

        int ntempo = ((int.Parse(tempo) * 100) / int.Parse(tempomax));

        if (tempo == tempomax || eaula.percentual == eaula.percentualmax || ntempo >= 95 )//ou perc ser maior 98%
        {
            eadaula aaula = (from x in DB.eadaula where x.eadcodaula == icodaula select x).FirstOrDefault();
            eadaula paula = (from x in DB.eadaula 
                             where x.eadcodcursomodulo == aaula.eadcodcursomodulo
                             where x.ordem == aaula.ordem + 1
                             select x).FirstOrDefault();

            if (paula != null)
            {
                //link = "eadVerAula.aspx?codaula=" + paula.eadcodaula + "&t=" + paula.eadcodmidia;
                HttpContext.Current.Response.Redirect("eadVerAula.aspx?codaula=" + paula.eadcodaula + "&t=" + paula.eadcodmidia,false);
                //Context.Response.StatusCode = 307;
                //Context.Response.AddHeader("Location", "<redirect URL>");

               // HttpContext.Current.Response.StatusCode = 307;

               // HttpContext.Current.Response.AddHeader("Location", "eadVerAula.aspx?codaula=" + paula.eadcodaula + "&t=" + paula.eadcodmidia);
            }
                //HttpContext.Current.Response.Redirect("eadVerAula.aspx?codaula=" + paula.eadcodaula + "&t=" + paula.eadcodmidia);
                //link = "eadVerAula.aspx?codaula=" + paula.eadcodaula + "&t=" + paula.eadcodmidia;
        }
        return "";
    }
document.location.href = url;