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

Asked

Viewed 37 times

0

I want to return a random value of the bank and already display in another tab, through a function. For when I click submit 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);
}

1 answer

0

It wouldn’t just be putting inside Success?

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.