Welcome Guest, Not a member yet? Register   Sign In
AJAX URL Composition
#1

[eluser]yyzSantaBarbara[/eluser]
Code:
$('#btn_login').click(function()
  {  
      console.log("Login has been clicked");
      $.post('<?php echo site_url('/login/validate_credentials'); ?>',
      {            
        'user':$('#user').val(),
        'pass':$('#pass').val(),
        'ajax':1    
      },      

      // when the Web server 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_filter'); ?&gt;';
         $.mobile.changePage( url, {
                type: "get",
                showLoadMsg : true
            });
        }
        else
        {        
         var x = '<p class="required">'+data+'</p>'
             $('#validation_message_target p').html(x);
        }
      }
    );
  });

I am making a simple JQuery Mobile AJAX POST and the POST is creating a URL on the browser that is not what I require.

For example:

This is generated:

http://localhost:82/CodeIgniter_2.1.3/in...rch_filter

When I would like it to be

http://localhost:82/CodeIgniter_2.1.3/in...rch_filter

I have done some searching on this issue and I cannot narrow down the solution so I thought I would ask this question here.

I have tried different ways of creating the POST URL: base_url(), site_url(), and hardcoded absolute URL. It leads me to believe that this is a CodeIgniter configuration settings that I need to set.

The problem with the current URL is that when I am in the stock_seach_filter page subsequent AJAX funtions do not get triggered because the URL is messed up. If I manually change the URL to what I have shown above then the subseqeunt URLs on the stock_search_filter page work as expected.

My website is running under Apache 2.2.21
#2

[eluser]yyzSantaBarbara[/eluser]
Code:
if (n > 0)
        {
            var url = '&lt;?php echo site_url('/activity/stock_search_filter'); ?&gt;';
         /*$.mobile.changePage( url, {
                type: "get",
                //changeHash:false,
                reloadPage:true,
                showLoadMsg:true
            });*/
           [removed] = url;    
        }
        else
        {        
         var x = '<p class="required">'+data+'</p>'
   $('#validation_message_target p').html(x);
        }

I figured out a solution. I don't think it will be ideal when I test on a mobile device, but for now it will suffix. I first tried adding changeHash:false and that removed the # sign but it did not change the URL to the redirected URL. It kept it on the same page. So I used some brute force and changed the DOM using the following,

Code:
"window
.locarion = url;"





Theme © iAndrew 2016 - Forum software by © MyBB