Welcome Guest, Not a member yet? Register   Sign In
I can't get the responce for ajax post call.
#1

[eluser]chefnelone[/eluser]
Hello.

I can't get the responce for ajax post call.(using jquery).
But this problem just happens in the remote server. In my locallhost works fine. :ohh:

I have the form:
Code:
<form id='test'>
<input type="text" name="xxx" value="test" />
<input type="submit" value="enviar"/>
</form>

the js:
Code:
$(document).ready(function() {
  $('#test').submit(function(eve) {
  eve.preventDefault();
     $.post('/shop/test' , $(this).serialize() , function(html){
     alert(html);
     //I can't get 'html' which should contain "Data from the method" text

  });
});

and the method in shop controller:
Code:
function test()
        {
            $data = "Data from the method";
                echo $data;
                $this->firephp->log( $data);
                // I get this, so the method is called from the javascript
        }

I cant's spot the mistake. ..
#2

[eluser]danmontgomery[/eluser]
Use firebug to capture any xmlhttprequests
#3

[eluser]chefnelone[/eluser]
thanks

You mean the Console?

As far as I understand the path to the method is correct. (but it is in red, I don't know why)

I even get the message from the method (using $this->firephp->log( $data ); )

How can it work fine in my locallhost but not in the remote server?

I'm blank. What can I do?


This is what I get in the Console(images for 'Sent' and 'Headers')
#4

[eluser]Eric Barnes[/eluser]
Now I don't know much about jquery but should it not be "success: function()" instead of just function?
#5

[eluser]SpooF[/eluser]
Have you tried calling the URI and making sure its not erroring?
#6

[eluser]chefnelone[/eluser]
[quote author="SpooF" date="1265942194"]Have you tried calling the URI and making sure its not erroring?[/quote]

Hello spoof. can you tell me how to do it please.
#7

[eluser]Jake Grice[/eluser]
I had this problem the other day on a simple email form that used Ajax with almost the exact same setup. (Serializing a form with $.post).

It just wouldn't alert the return value.

After debugging it, and getting it to work, it turned out to be an error in the native mail function so I used SMTP.


Try making your test function echo out text without doing anything else.

What is the URL of the project?
#8

[eluser]chefnelone[/eluser]
I started again from a clean codeigniter application and I got it working but with this problem:
In the js function I must to use this line:
$.post('index.php/test/processFormAjax' , $(this).serialize() , function(html){...

But... it doesn't work if I change that line to this:
$.post( base_url + 'test/processFormAjax' , $(this).serialize() , function(html){...
or
$.post('/test/processFormAjax' , $(this).serialize() , function(html){...
or
$.post('/processFormAjax' , $(this).serialize() , function(html){...



I create this very simple example:

The example uses this code:

'test.php' Controller:

Code:
class Test extends Controller {

    function Test()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->load->view('test');
    }
    
    function processFormAjax(){
    
        echo "Data sent from the method";    
    
    }
}

test.php View
Code:
<html>
<head>

script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"> script

script


base_url = '<?php echo base_url(); ?>';

$(document).ready(function() {

   $('#test').submit(function(eve) {
   eve.preventDefault();

        $.post('index.php/test/processFormAjax' , $(this).serialize() , function(html){
        //$.post( base_url + 'test/processFormAjax' , $(this).serialize() , function(html){

        alert(html);

        });

    });
});


script

</head>
<body>

<?php
$attributes = array('id' => 'test');
echo form_open('test/processForm', $attributes);
?>
    
    <input type="text" name="field1"  value="any value"/>
    <input type="submit" value="Submit" />

</form>


</body>
</html>
#9

[eluser]Unknown[/eluser]
change the name of the function from 'test' to anything..

I don't know why but codeigniter ignores functions with the name 'test'...




Theme © iAndrew 2016 - Forum software by © MyBB