• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ajax Request

#21
[eluser]uptime[/eluser]
[quote author="Nutan Lade" date="1219790109"]Here in the Ajax call I am sending a value userId.I need this value to enter into db.But when I am using $_post['userId'] I am getting an error and it is

Undefined index: userId[/quote]

First of all, you should use $_POST[] instead of $_post[] (uppercase).

If it still doesn't work, keep reading...

* Are you sure you're sending it as post (and not get)?
* Do you have that AJAX page online?
* Are you sure the field name is userId? (this is case-sensitive ! )

Add this line BEFORE that line in which you try to use "$_post['userId']":
Code:
var_dump($_POST); exit;
And show us the results.

#22
[eluser]Nutan Lade[/eluser]
I tried both the cases.i.e upper and lower case.
still the same error

A PHP Error was encountered

Severity: Notice

Message: Use of undefined constant userId - assumed 'userId'

when using this code it was returing array(0){}
Code:
var_dump($_POST); exit;

Code:
function submitMovie(movieId){
  //    alert(movieId);
    var url = "<?=base_url()?>index.php/gadgets/addMovie/"+movieId;
        
        var msgBox = "movieLink_"+movieLink;

        new Ajax.Request(url, {
        method: 'post',
        parameters: {userId: 1},
        onComplete: function(addmovie){
          var response = addmovie.responseText || "no response text";
          document.getElementById(msgBox)[removed] = response;        
        },
        onFailure: function(){ alert('Something went wrong...') }
          });
  }

and the server code is
Code:
function addMovie(){
        echo "hi";        
        var_dump($_POST); exit;
        //echo $_POST[userId];
        
    }

it was returning hi and array(0){}

#23
[eluser]uptime[/eluser]
Do you see any errors on the Error Console or in Firebug's console?

#24
[eluser]Nutan Lade[/eluser]
I didn't find any error in firebug console

#25
[eluser]uptime[/eluser]
Does it work without AJAX?

#26
[eluser]Nutan Lade[/eluser]
Yes it is working without ajax.When I am making direct request to the server.

And I had one more problem with this have a look at the code:

Code:
function addMovieName(){          
  var movieName = addMovieForm.autocomplete.value;
  //alert(movieName);
    var url = "<?=base_url()?>index.php/gadgets/addMovieByName/"+movieName+"/1";
        //alert(url);
        new Ajax.Request(url, {
        method: 'post',
        parameters: {userId: 1},
        onComplete: function(addMovieName){
          var response = addMovieName.responseText || "no response text";
         // document.getElementById(indicator1)[removed] = response;
            alert("Success! \n\n" + response);
        },
        onFailure: function(){ alert('Something went wrong...') }
          });
  }
<form id="addMovieForm" action="<?=base_url()?>index.php/gadgets/addMovieByName" method="post">
<input type="text" id="autocomplete" name="autocomplete" >
<input type="submit" value="Add" id="addMovie" name="addMovie" >

on the server

Code:
function addMovieByName(){
        echo "hello";
        
        var_dump($_GET); exit;
        
            }

I am getting error in the console prototype is not defined.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.