Welcome Guest, Not a member yet? Register   Sign In
Ajax Request
#1

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

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

[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
#4

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

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

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

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

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

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

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




Theme © iAndrew 2016 - Forum software by © MyBB