CodeIgniter Forums

Full Version: Ajax Request
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3

El Forum

[eluser]Nutan Lade[/eluser]
Code:
function submitMovie(){
      alert("hi");
    var url = "<?=base_url()?>index.php/gadgets/addMovie";
        //alert(url);
        new Ajax.Request(url, {
        method:'post',
        parameters: {userId: 1},
        onSuccess: function(movieSubmit){
          var response = movieSubmit.responseText || "no response text";
          document.getElementById('movieSubmitMsg')[removed] = response;
         // alert("Success! \n\n" + response);
        },
        onFailure: function(){ alert('Something went wrong...') }
          });
  }

How can I get the parameters values on the server side.

El Forum

[eluser]Pascal Kriete[/eluser]
They'll be in the $_POST array, so you have two options:
Code:
// Conventional PHP
$temp = $_POST['userId'];

// CodeIgniter Input class
$temp = $this->input->post('userId');

El Forum

[eluser]Nutan Lade[/eluser]
Code:
function submitMovie(movieId){
  //    alert(movieId);
    var url = "<?=base_url()?>index.php/gadgets/addMovie/"+movieId;
    //    alert(url);
        new Ajax.Request(url, {
        method: 'post',
        parameters: {userId: 1},
        onComplete: function(addmovie){
          var response = addmovie.responseText || "no response text";
         // document.getElementById('movieSubmitMsg')[removed] = response;
         alert("Success! \n\n" + response);
        },
        onFailure: function(){ alert('Something went wrong...') }
          });
  }

function addMovie(){
        $this->Movies_db->add_movie();
        echo "addMovie";
        echo $_POST['userId'];

    }


but the server is not returing anything

El Forum

[eluser]Pascal Kriete[/eluser]
Nothing at all? What happens if you go to the url manually?

El Forum

[eluser]uptime[/eluser]
I don't know what's the issue but have you tried to use Firebug to make sure the servers gets the right URI / vars?

El Forum

[eluser]Nutan Lade[/eluser]
When I am trying the url manually I am getting the addMovie

El Forum

[eluser]mdowns[/eluser]
As uptime suggested, check the uri used in the Ajax call.

El Forum

[eluser]Nutan Lade[/eluser]
I want to submit values to server.Is that any other ajax method to do that.

El Forum

[eluser]uptime[/eluser]
[quote author="Nutan Lade" date="1219780348"]I want to submit values to server.Is that any other ajax method to do that.[/quote]

Are you using an AJAX library? Or is it plain JS?

El Forum

[eluser]Nutan Lade[/eluser]
I am using Ajax library.
Pages: 1 2 3