Welcome Guest, Not a member yet? Register   Sign In
load a view in a div jquery
#1

[eluser]BlueDom[/eluser]
Hello big part of my application is designed with ajax
I am now trying to load a view in a div using ajax jQuery works
But I have no idea how to do this

Someone could help me?
#2

[eluser]BlueDom[/eluser]
No response to this? please
I searched google and find nothing
#3

[eluser]danmontgomery[/eluser]
Something like

Code:
$.get('path/to/somewhere', function(data) { $('#my_div').html(data); });

or

Code:
$.post('path/to/somewhere', { var_1: 'some_value', var_2: 'some_other_value' }, function(data) { $('#my_div').html(data); });

Where path/to/somewhere would be the path to a controller function which echoes the view.

http://api.jquery.com/jQuery.get/
http://api.jquery.com/jQuery.post/
#4

[eluser]BlueDom[/eluser]
Ok thanks
But the question now is how the driver must go

now I have it in this way, but does not work


the view


Code:
function sendForm(url,div) {
var str = $("#Formulario").serialize();
    $.ajax({
        type: "POST",
        url: "/report/form",
        data: str,
        dataType: "json",
        success: function(datos){
                                    $("#Rasult").html(datos);
                  }
        });
                        
}

Then controller

Code:
function form(){

echo json_encode( $this->load->view("listados") );

}
#5

[eluser]danmontgomery[/eluser]
What's the point of running json_encode on a string? All that does is wrap the string in quotes...

What's in the listados view? What does "does not work mean"? Are you getting javascript errors? If so, what are they?

Details, please Tongue
#6

[eluser]BlueDom[/eluser]
Ok thanks I solved but I can not send the form to interpret json
$ This-> load-> view ();

Finally finished with this.


the View
Code:
function sendForm(url,div) {

                var str = $("#Formulario").serialize();
                $.ajax({
                                type: "POST",
                                url: /report/form,
                                data: str,
                                success: function(datos){
                                            $("#Rasult").html(datos);

                                  }
                        });

The controller

Code:
function form(){

$this->load->view("Listado");
}
#7

[eluser]Phil Sturgeon[/eluser]
That's the long way to do it.

Code:
$("#Rasult").load('/report/form', $("#Formulario").serialize() );

Much nicer :-)




Theme © iAndrew 2016 - Forum software by © MyBB