CodeIgniter Forums
Ajax Request - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Ajax Request (/showthread.php?tid=11075)

Pages: 1 2 3


Ajax Request - El Forum - 08-25-2008

[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.


Ajax Request - El Forum - 08-25-2008

[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');



Ajax Request - El Forum - 08-25-2008

[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


Ajax Request - El Forum - 08-25-2008

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


Ajax Request - El Forum - 08-25-2008

[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?


Ajax Request - El Forum - 08-26-2008

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


Ajax Request - El Forum - 08-26-2008

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


Ajax Request - El Forum - 08-26-2008

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


Ajax Request - El Forum - 08-26-2008

[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?


Ajax Request - El Forum - 08-26-2008

[eluser]Nutan Lade[/eluser]
I am using Ajax library.