How to put the content of an Ajax Post (reply received after post) in a popup? (post sent through an extension)

Asked

Viewed 137 times

0

Hi. I need to put the answer to an ajax post in a popup using javascript. Anyone have any idea? Is it possible to do this? It works like this: When doing the post (variable.send(...);), it would show the response content (which comes back from the server after processing the data) in a new pop-up.

1 answer

0

Dude has several ways to do this. Just you get the callback of the request. See below for an example using Asp Net MVC:

Code you will put in your view with the ajax request.

$.ajax({
   type: "GET",
   url: "Home/Index", //Endereço do controller / action
   contentType: "application/json" //Irá retornar um json no callback,
   success: function(data){ //Se ocorrer tudo certo com a requisição
       //Aqui você trabalha o resultado retornado pelo servidor
       //Como retornou um json vc pode acessar as propridades através data.propriedade
       alert('Resultado do servidor' + data.retorno);
   }
});

Not the controller would look like this:

public ActionResult Index(){
    //declarando um tipo para retornar para view (classe logo abaixo)
    var retorno = new ClasseA(){
        Id = 1,
        retorno = 'retorno'
    };
    return Json(retorno, JsonRequestBehavior.AllowGet)
}

public class ClasseA{
   public int Id {get; set;}
   public string retorno { get; set;}
}

Browser other questions tagged

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