How do I return a random value from my database already displaying on another tab?

0

I want to return a random value from the bank and already display in another tab, through a function. For when I click on send already calls this function.

Controller

public ActionResult RetornarVideoAleatorio(int id) 
    {
        var lista = db.Videos.Where(a => a.Id == id).FirstOrDefault();
        return View(lista);
    }

HTML

<section id="main"><form>
<input type="text" id="titulo" name="titulo" value="" required="" placeholder="Titulo" />

<input type="text" id="video-url" name="url" required="" value="" placeholder="url" />

<button id="submit" onclick="funcaoOnclick();">Enviar Video</button>
</form>
</section>

Javascript

function RetornarUrl(id) {

    var url = "/Video/RetornarVideoAleatorio" + id;

    $.ajax({
        url: url
        , type: "GET"
        , data: { id: id }
        , datatype: "Json"
        , success: function (data) {
            alert("retornou");
        },
        error: function () {
            alert("Erro");
        }
    });

}

function funcaoOnclick() {
    SalvarItens()
    RetornarUrl(id);
}
    
asked by anonymous 04.09.2018 / 01:07

1 answer

0

Would not it just put in success?

$.ajax({
        url: url
        , type: "GET"
        , data: { id: id }
        , datatype: "Json"
        , success: function (data) {
            alert("retornou");
        },
        error: function () {
            alert("Erro");
        },
success: function (){
 funcaoOnclick();
    }
    });
    
04.09.2018 / 14:06