Welcome Guest, Not a member yet? Register   Sign In
AJAX Post Succeeds on localhost but fails on PROD Apache server
#1

[eluser]yyzSantaBarbara[/eluser]
The code listed below successfully POSTS using JQUERY AJAX on my localhost. I am creating a JQueryMobile web site. However, when I moved this web site to the production server that is on the internet I have problems getting the $.(Post) to execute. I have looked in the debugger tools on IE and chrome and cannot see the POST call go through on the production server. On localhost the same code works as expected.

Has anybody encountered such a problem. I am using the CI version 2.1.3 on both local and Production. I forgot to check the versions of Apache but I believe the Production version is a little more recent. I think the problem is likely a CI configuration settings that I am missing, though both the local and production servers are using the same configuration files, expect for the base URL setting.

Code:
$(document).ready(function()
{
$("#validate_credentials").validate();
});

$('#btn_login').click(function()
{              
console.log("Login has been clicked: " + '<?php echo site_url('/login/validate_credentials'); ?>');

  $.post('<?php echo site_url('/login/validate_credentials'); ?>',
  {                                        
    'user':$('#user').val(),
    'pass':$('#pass').val(),
    'ajax':1                  
  },      

  // When CodeIgniter responds to the request
  function(data)
  {
    console.log("validate_credentials returned: "+ data);

    // clear any message that may have already been written
    $('#validation_message_target p').html('<p></p>');

    var n=data.search("&lt;title&gt;Welcome to CodeIgniter&lt;/title&gt;");    
    if (n > 0)
    {
   var url = '&lt;?php echo site_url('/activity/stock_search'); ?&gt;';
    $.mobile.changePage( url, {
    type: "get",
    showLoadMsg : true
   });
    }
    else
    {                      
   var x = '<p class="required">'+data+'</p>'
   $('#validation_message_target p').html(x);
    }
});
});
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

Have you checked that you're not getting any Javascript errors? I think you might have the syntax a bit wrong. Please try this:
Code:
$('#btn_login').click(function() {              
    console.log("Login has been clicked: " + '&lt;?php echo site_url('/login/validate_credentials'); ?&gt;');

    $.post('&lt;?php echo site_url('/login/validate_credentials'); ?&gt;', {                                        
        'user':$('#user').val(),
        'pass':$('#pass').val(),
        'ajax':1                  
    })
    // When CodeIgniter responds to the request
    .done(function(data) {
        console.log("validate_credentials returned: " + data);

        // clear any message that may have already been written
        $('#validation_message_target p').html('<p></p>');

        var n=data.search("&lt;title&gt;Welcome to CodeIgniter&lt;/title&gt;");    
        if (n > 0) {
            var url = '&lt;?php echo site_url('/activity/stock_search'); ?&gt;';
            $.mobile.changePage( url, {
                type: "get",
                showLoadMsg : true
            });
        } else {                      
            var x = '<p class="required">'+data+'</p>'
            $('#validation_message_target p').html(x);
        }
    });
});
#3

[eluser]yyzSantaBarbara[/eluser]
Thanks for your suggestion. However, it did not resolve the problem. The issue is that the AJAX request

$.post('&lt;?php echo site_url('/login/validate_credentials'); ?&gt; ....

does not get transferred to the server. I am watching the network trace. The same test and trace on the local development server works perfectly. I am going to spend an hour or so trying to figure this out tonight or pay and get EllisLab customer support involved tommorow.
#4

[eluser]yyzSantaBarbara[/eluser]
Well right after my previous post I thought I would try my tests again. IE9 failed as in the past. Then I tried Google Chrome and this time my Ajax call worked. Firefox worked and so did Windows Phone 8. Certainly strange that Chrome is working now and not so 2 days ago, but I won't complain.

So for now I am in business and can continue my iterative development process. I certainly do not have any clue as to why IE9 still does not work on this particular server but does so on my local development server.
#5

[eluser]TheFuzzy0ne[/eluser]
Have you tried clearing your browser cache?
#6

[eluser]yyzSantaBarbara[/eluser]
I am at work now and not at home. I tried from my work with IE9 and now I am able to get everything working on IE9. So it was indeed a browser cache issue.

The reason that this did not seem like an obvious solution to me was that I tried IE9 from my server at home connecting to the PROD server on the internet. That failed as I have previously mentioned.

I then logged onto the PROD server using a RDP connection and launched an IE9 browser locally on the PROD server. This also failed. So both my IE9 and PROD server's IE9 browser cache must require a clearing since the site works from my work IE9 browser.

Thanks for your help.




Theme © iAndrew 2016 - Forum software by © MyBB