How to put the contents of an Ajax Post (response received after the post) into a popup? (post sent through an extension)

0

Hi. I need to put the response of a post ajax into a popup using javascript. Anyone have ideas? is it possible to do that? It works like this: By doing the post (variavel.send (...);), it would show the response content (which comes back from the server after processing the data) into a new popup.

    
asked by anonymous 26.03.2015 / 00:30

1 answer

0

Dude has several ways to do this. Just get the request callback. Here's an example using Asp Net MVC:

Code that 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);
   }
});

In the controller it 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;}
}
    
26.03.2015 / 15:00