1

I have a website on which i am using sub domain to design the shopping area.

Example Website is http://avc.com and subdomain is http://shop.avc.com/. Subdomain points to shop folder onto the server.

Now, i have a login script that resides in main website folder not in subdomain.

Ps: At the time of checkout i am giving option to user login i.e. the URL for checkout will be http://shop.avc.com/checkout and the Login script is at http://avc.com/login/verify.php

Jquery used for AJAX call from subdomain is:

$.ajax({
        url: '../login/verify.php',
        type: 'POST',
        data: dataString,
        beforeSend: function(){
            $("#loadingslogin").show();
        },

        complete: function(){
            $("#loadingslogin").hide();
        },
        success: function(response) {
            if(response != 5){
                $('#responsesign').html("<p class='alert alert-danger'>Oops! 
                Something wrong happened.").fadeIn().delay(15000).fadeOut();
            }
            else{
                $("input[type='text']").val('');
                $("input[type='password']").val('');
                $("#loadingslogin").hide();
                window.location.replace('checkout');
            }
        }            
    });

But the verify.php file is not getting executed. Any solutions please?

Gags
  • 3,759
  • 8
  • 49
  • 96
  • Is that just a typo in the path: `'..login/verify.php'`? – jeroen Apr 20 '15 at 16:06
  • oops. it was a typo :) – Gags Apr 20 '15 at 16:07
  • Cross-domain issues, any messages in the console? – jeroen Apr 20 '15 at 16:08
  • no messages... just in network tab the file just shows empty response – Gags Apr 20 '15 at 16:08
  • If there is an empty response, it seems it is getting executed. Check the server log, you should be able to narrow down the problem to the js or the php. – jeroen Apr 20 '15 at 16:12
  • nop... the file is not available.. this was problem at my local also and i solved by pointing to right file... the URL is itself `http://shop.avc.com/login/verify.php` on AJAX req – Gags Apr 20 '15 at 16:13
  • You are mixing two different issues. you can not link to your `/login/verify.php` using physical address in `javascript`. in your hard drive, this relation between your files is correct and if you were supposed to link them using `php` you had to use this address, but you have to use `virtual addressing` for `javascripts`. if you are in this address `http://shop.avc.com/checkout` and use `javascrip` to access this link: `../login/verify.php` then your `javascript` will look in this address: `http://shop.avc.com/login/` for your `verify.php` which does not exist. – EhsanT Apr 20 '15 at 19:10
  • Capture the error response. Add `error: function(xmlhr, errorStr) { // do something }` – Twisty Apr 20 '15 at 21:12
  • @EhsanT . please suggest a solution also – Gags Apr 21 '15 at 03:37
  • 2
    OK, if you search in SO, you can find bunch of questions regarding the same issue. there are different solutions but I myself like [this hack](http://stackoverflow.com/questions/648899/a-question-about-cross-domain-subdomain-ajax-request/11147005#11147005) which is very easy to implement. you will get the idea. give it a try and if you had more questions, I'll be happy to help you. [here](http://stackoverflow.com/questions/18990872/how-to-make-a-subdomain-ajax-call-with-jquery-without-iframes) you can find another answer, and the last comment in the answer is also pretty. – EhsanT Apr 21 '15 at 04:07
  • @EhsanT .. can u post this as an answer please – Gags Apr 21 '15 at 06:00
  • Hack `http://stackoverflow.com/questions/648899/a-question-about-cross-domain-subdomain-ajax-request/11147005#11147005` worked for me – Gags Apr 21 '15 at 06:10

1 Answers1

1

As EhsanT has not posted his solution as an answer. So i am answering myself

Fiddle Link

worked for me well

Community
  • 1
  • 1
Gags
  • 3,759
  • 8
  • 49
  • 96