• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Jquery - issue with post method

#1
[eluser]Piekarz[/eluser]
Hi, I try to use jQuery in my code. I got the html select/option list like this:
Code:
<select class="emaillist">
    <option value="emails"></option>
&lt;!-- list of email adresses... --&gt;
    </select>
I create jQuery function like this:
Code:
$("select.emaillist").change(function() {
$.ajax({
        type: "POST",
        url: "http://localhost/mgr/index.php/welcome/post_ajax",
        dataType: "json",
        data: "email="+$(this).text(),
        cache:false,
        success:
          function(data){
            $("div.leftecho").text(data);
          }
        
        });
        return false;
});
and in my welcome controller I put this code:
Code:
public function post_ajax(){
            if(isset($_POST['email'])){
                $this->session->set_userdata('selectedemail',$_POST['email']);
                return true;
            }
        }

Could anyone say my why this code doesn't work? When I add this code to my jQuery function:
Code:
statusCode: {
    404: function() {
      alert("page not found");
    }
  }
It always shows alert message, why ajax can't verify my url well? Is it the problem?

#2
[eluser]ojcarga[/eluser]
Are you sure you can access this url "http://localhost/mgr/index.php/welcome/post_ajax"?

Try to access it through the browser and set an "else" for you to check:

Code:
public function post_ajax(){
    if(isset($_POST['email'])){
        $this->session->set_userdata('selectedemail',$_POST['email']);
        //return true;
        echo "COOL!"; //instead of return you must echo something
    }else{
        echo "Direct access...";
    }
}

Cheers!

#3
[eluser]Piekarz[/eluser]
Yeah, I am sure. I changed code like you wrote and i got a message in browser:
"Direct access..."


You know, I don't really know what I changed but it starts to work o.O
Thx for reply.

The most funny thing is that I tried to resolve this issue from few days and when I asked you, it starts to work. Epic weird but thx for help :]


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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