-1

for some reason my $.ajax() is posting but not providing a success message which is rather strange because i am using the same code from another application just with different values

$("#submit").click(function(e)
    e.preventDefault();
    var email = $("#email_address").val();
    var url = "<?=base_url()?>" + "account/validate_registration";
    $.ajax({
        type:"POST",
        url:url,
        data:{"email_address":email},
        success: function(res,status){
            alert(res);
        }
    });
});

Sometimes chrome developer console displays the response of the php file which is

print_r($_POST);

I cant understand how it works in one application and not in this one

Mickaël Leger
  • 3,426
  • 2
  • 17
  • 36
chris keenan
  • 23
  • 1
  • 9
  • 3
    Does the request show that it returned successfully in the developer tools network tab? – Taplar Mar 13 '18 at 15:56
  • 2
    I would advise you to include `error: function(response){alert(response);}` as well to make sure that the ajax returns success, and not error. Hope this helps! – N. Ivanov Mar 13 '18 at 15:57
  • Yet what is the actual error that you getting from the ajax call? – k0pernikus Mar 13 '18 at 15:57
  • I'm ok with Ivanov you should add the error part with `console.log(response);` to have better idea of what's not working. And where is your problem? You don't go to the success part of your ajax call? – Mickaël Leger Mar 13 '18 at 15:58
  • Possible duplicate of [Ajax success event not working](https://stackoverflow.com/questions/1969476/ajax-success-event-not-working) – devlin carnate Mar 13 '18 at 15:59
  • try only success: function(res){ – Roy Bogado Mar 13 '18 at 16:02
  • sometimes the response in the network tab prints of the post sometimes it doesnt there's times i see it posting but then times i see it has'nt its strange i will try console.log see what that sends – chris keenan Mar 13 '18 at 16:09
  • i rewrote it and put the error: in and it worked however when i removed the error: it still worked so i'm going to investigate where the typo was thanks – chris keenan Mar 13 '18 at 16:29

1 Answers1

0
$.ajax({
        type:"POST",
        url:url,
        dataType: "json", 
        data:{"email_address":email},
        success: function(res,status){
            alert(res);
        }
    });



this url should return json data (var url = "<?=base_url()?>" + "account/validate_registration";)
Mathan Kumar
  • 929
  • 9
  • 19