2

I need to retrieve the parameter passed in answer to a AJAX request.

Using this code:

$.ajax({
    url: 'https://example.com/login/',
    data: { username: User, password: Pass },
    type: 'get',
    success: function (output) {
        ...
    }
});

The page return some parameters i.e. https://example.com/login/?res=success&...

How can I get those parameter instead of the page content in "output"?

I add some information.

We use an external hotspot service provider in order to provide wifi access to our customers. The service is hosted on a website i.e. www.example.com We need to provide our customers the ability to enter their credentials from our website. The above code is in our website and the ajax request is directed to the login page of the hotspot service provider. When I send the request, the page return the parameter ?res=success. I need to get this parameter after my ajax request.

user2272143
  • 469
  • 5
  • 22
  • what do you want to retrieve? – Nitesh Jul 31 '17 at 02:50
  • I need to retrieve the parameter res=success from the page in answer to my ajax request - https://example.com/login/?res=success&... – user2272143 Jul 31 '17 at 02:53
  • You want to retrieve this parameter from current URL? – Nitesh Jul 31 '17 at 03:00
  • @Nitesh When I use the browser and enter the URL with parameters ?username=user&password=pass the page is opened and URL change with parameter ?res=success . I need to retrieve this parameter after my ajax request – user2272143 Jul 31 '17 at 03:08
  • Why would you even use ajax for same page request? just use submit then check if your page has those parameters in the url. If you really want it to be ajax, it's better to have separate url/endpoint for it with a respond as a json. – perseusl Jul 31 '17 at 03:11
  • @perseusl Because I dont want to be redirected to that page. I need to send the request and get the parameters remaining in my current page. – user2272143 Jul 31 '17 at 03:16
  • @user2272143 just create a separate end point that check for those credentials e.g. 'https://example.com/validate/ which response with json data that contains your success property that you want to get. That would be a lot easier. – perseusl Jul 31 '17 at 03:19
  • I cannot create anything on that site because I'm try to get authenticated on an external website from my website – user2272143 Jul 31 '17 at 03:24
  • I appreciate yours suggestions but please can someone simply tell me if it is possible to get those parameters from ajax request instead to provide alternative solutions? Thanks – user2272143 Jul 31 '17 at 03:28
  • 1
    can you provide an screenshot of the http response headers of your ajax request (in the dev tool console for example). if you find that url containing the parameter you wanna retrieve in one of the header, you could use the getResponseHeader() to get it as in this Stack overflow answer: https://stackoverflow.com/questions/11440918/jquery-get-ajax-response-headers – erwan Jul 31 '17 at 04:09
  • @erwan Thankyou very much your comment bring me on the right direction. Please post as answer so I can mark the question as solved. Now I have another problem about crossdomain but I think is a different question so I will open a new question. – user2272143 Jul 31 '17 at 05:17

0 Answers0