0

i'm submitting a form through ajax. it worked perfectly when the server script was hosted on my local computer. Now i've uploaded it unto my remote hosting server and it fails to do the call

when the file was on the local machine the script looked like this

<script language="javascript">

$(document).ready(function(){
    $("form").on('submit',function(event){
        event.preventDefault();

        data = $(this).serialize();
        $.ajax({
        type: "POST",
        url: "login.php",
        data: data
        }).success(function(msg) {
   $('#message').html(msg);


        });
    });
});

</script>

Remote hosting server

<script language="javascript">

$(document).ready(function(){
    $("form").on('submit',function(event){
        event.preventDefault();

        data = $(this).serialize();
        $.ajax({
        type: "POST",
        url: "http://mysite/login.php",
        data: data
        }).success(function(msg) {
   $('#message').html(msg);


        });
    });
});

</script>

Now when i click on the submit button nothing happens

i_user
  • 511
  • 1
  • 4
  • 21

2 Answers2

3

First off you cannot pass post variables to different servers if that is what you are trying to do. Just trying to clarify. You cannot fill out a form on abc.com and run your JS / AJAX request and expect the post url to be wxy.com If you are trying to do that it will not work. If not. Then simply fix the url like so.

This:

    url: "http://mysite/login.php",

Needs to be This:

    url: "login.php",

Assming that the location of the JS script executing the AJAX call and login.php reside in the same directory. if not, just make a relative path. i.e.

    url: "sub_directory/login.php",

and all will work just fine.

0

For me, you are not doing any cross-site domain request, nor any other thing...

<script language="javascript">

$(document).ready(function(){
    $("form").on('submit',function(event){
        event.preventDefault();

        data = $(this).serialize();
        $.ajax({
          type: "POST",
          url: "login.php",
          data: data
        }).success(function(msg) {
   $('#message').html(msg);


        });
    });
});

</script>

Your "local" script was already good

Deblaton Jean-Philippe
  • 11,188
  • 3
  • 49
  • 66