How do I modify the response url of an ajax function?











up vote
0
down vote

favorite












I have an ajax function, which on success redirects to the response returned from the url:



document.getElementById("button1").addEventListener("click", function (e) {
e.preventDefault();
$.ajax({
url: 'http://localhost:8080/someLoginUrl',
method: 'GET',
crossDomain : true,
xhrFields: {
withCredentials: false
},
success: function(response){
window.location.href = response;
}
});
});


The response, which is returned by http://localhost:8080/someLoginUrl is just a webpage, containing a url:



This is the html of the response page:



<html><head></head><body>https://localhost:8080/anotherLogin</body></html>


So, once I click my button button1, instead of redirecting to http://localhost:8080/someLoginUrl, it redirects to https://localhost:8080/anotherLogin, which is the desired behavior for me.
However, I want to do a small manipulation on the response inside the success function - I want to change the protocol from https to http. How do I do that?



I tried response = response.replace('https', 'http'); but this did not change anything.










share|improve this question




















  • 1




    @ArielAlvarado first arg in replace method is source and second one is target. So your solution will not work.
    – Ms.Tamil
    Nov 7 at 10:58










  • @Ms.Tamil it worked, thanks!
    – sammy333
    Nov 7 at 11:00










  • i'm always a bit surprised when I hear about redirect as response from Ajax. You don't need ajax to do what you want to do...
    – Lelio Faieta
    Nov 7 at 11:14















up vote
0
down vote

favorite












I have an ajax function, which on success redirects to the response returned from the url:



document.getElementById("button1").addEventListener("click", function (e) {
e.preventDefault();
$.ajax({
url: 'http://localhost:8080/someLoginUrl',
method: 'GET',
crossDomain : true,
xhrFields: {
withCredentials: false
},
success: function(response){
window.location.href = response;
}
});
});


The response, which is returned by http://localhost:8080/someLoginUrl is just a webpage, containing a url:



This is the html of the response page:



<html><head></head><body>https://localhost:8080/anotherLogin</body></html>


So, once I click my button button1, instead of redirecting to http://localhost:8080/someLoginUrl, it redirects to https://localhost:8080/anotherLogin, which is the desired behavior for me.
However, I want to do a small manipulation on the response inside the success function - I want to change the protocol from https to http. How do I do that?



I tried response = response.replace('https', 'http'); but this did not change anything.










share|improve this question




















  • 1




    @ArielAlvarado first arg in replace method is source and second one is target. So your solution will not work.
    – Ms.Tamil
    Nov 7 at 10:58










  • @Ms.Tamil it worked, thanks!
    – sammy333
    Nov 7 at 11:00










  • i'm always a bit surprised when I hear about redirect as response from Ajax. You don't need ajax to do what you want to do...
    – Lelio Faieta
    Nov 7 at 11:14













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have an ajax function, which on success redirects to the response returned from the url:



document.getElementById("button1").addEventListener("click", function (e) {
e.preventDefault();
$.ajax({
url: 'http://localhost:8080/someLoginUrl',
method: 'GET',
crossDomain : true,
xhrFields: {
withCredentials: false
},
success: function(response){
window.location.href = response;
}
});
});


The response, which is returned by http://localhost:8080/someLoginUrl is just a webpage, containing a url:



This is the html of the response page:



<html><head></head><body>https://localhost:8080/anotherLogin</body></html>


So, once I click my button button1, instead of redirecting to http://localhost:8080/someLoginUrl, it redirects to https://localhost:8080/anotherLogin, which is the desired behavior for me.
However, I want to do a small manipulation on the response inside the success function - I want to change the protocol from https to http. How do I do that?



I tried response = response.replace('https', 'http'); but this did not change anything.










share|improve this question















I have an ajax function, which on success redirects to the response returned from the url:



document.getElementById("button1").addEventListener("click", function (e) {
e.preventDefault();
$.ajax({
url: 'http://localhost:8080/someLoginUrl',
method: 'GET',
crossDomain : true,
xhrFields: {
withCredentials: false
},
success: function(response){
window.location.href = response;
}
});
});


The response, which is returned by http://localhost:8080/someLoginUrl is just a webpage, containing a url:



This is the html of the response page:



<html><head></head><body>https://localhost:8080/anotherLogin</body></html>


So, once I click my button button1, instead of redirecting to http://localhost:8080/someLoginUrl, it redirects to https://localhost:8080/anotherLogin, which is the desired behavior for me.
However, I want to do a small manipulation on the response inside the success function - I want to change the protocol from https to http. How do I do that?



I tried response = response.replace('https', 'http'); but this did not change anything.







javascript jquery ajax






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 11:03









executable

899221




899221










asked Nov 7 at 10:54









sammy333

4823822




4823822








  • 1




    @ArielAlvarado first arg in replace method is source and second one is target. So your solution will not work.
    – Ms.Tamil
    Nov 7 at 10:58










  • @Ms.Tamil it worked, thanks!
    – sammy333
    Nov 7 at 11:00










  • i'm always a bit surprised when I hear about redirect as response from Ajax. You don't need ajax to do what you want to do...
    – Lelio Faieta
    Nov 7 at 11:14














  • 1




    @ArielAlvarado first arg in replace method is source and second one is target. So your solution will not work.
    – Ms.Tamil
    Nov 7 at 10:58










  • @Ms.Tamil it worked, thanks!
    – sammy333
    Nov 7 at 11:00










  • i'm always a bit surprised when I hear about redirect as response from Ajax. You don't need ajax to do what you want to do...
    – Lelio Faieta
    Nov 7 at 11:14








1




1




@ArielAlvarado first arg in replace method is source and second one is target. So your solution will not work.
– Ms.Tamil
Nov 7 at 10:58




@ArielAlvarado first arg in replace method is source and second one is target. So your solution will not work.
– Ms.Tamil
Nov 7 at 10:58












@Ms.Tamil it worked, thanks!
– sammy333
Nov 7 at 11:00




@Ms.Tamil it worked, thanks!
– sammy333
Nov 7 at 11:00












i'm always a bit surprised when I hear about redirect as response from Ajax. You don't need ajax to do what you want to do...
– Lelio Faieta
Nov 7 at 11:14




i'm always a bit surprised when I hear about redirect as response from Ajax. You don't need ajax to do what you want to do...
– Lelio Faieta
Nov 7 at 11:14












1 Answer
1






active

oldest

votes

















up vote
0
down vote













May Be I understand your Question ! You want your success Response data to your Same page where this action took place



First You have to create a dive with id <div id=res_data> </div> and place this div where you want to show your response data .



Then Your Final code is



document.getElementById("button1").addEventListener("click", function (e) {
e.preventDefault();
$.ajax({
url: 'http://localhost:8080/someLoginUrl',
method: 'GET',
crossDomain : true,
xhrFields: {
withCredentials: false
},
success: function(response){
$('#res_data').val(response);
}
});
});


Tuned me if you not find this helpful .






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53188071%2fhow-do-i-modify-the-response-url-of-an-ajax-function%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    May Be I understand your Question ! You want your success Response data to your Same page where this action took place



    First You have to create a dive with id <div id=res_data> </div> and place this div where you want to show your response data .



    Then Your Final code is



    document.getElementById("button1").addEventListener("click", function (e) {
    e.preventDefault();
    $.ajax({
    url: 'http://localhost:8080/someLoginUrl',
    method: 'GET',
    crossDomain : true,
    xhrFields: {
    withCredentials: false
    },
    success: function(response){
    $('#res_data').val(response);
    }
    });
    });


    Tuned me if you not find this helpful .






    share|improve this answer

























      up vote
      0
      down vote













      May Be I understand your Question ! You want your success Response data to your Same page where this action took place



      First You have to create a dive with id <div id=res_data> </div> and place this div where you want to show your response data .



      Then Your Final code is



      document.getElementById("button1").addEventListener("click", function (e) {
      e.preventDefault();
      $.ajax({
      url: 'http://localhost:8080/someLoginUrl',
      method: 'GET',
      crossDomain : true,
      xhrFields: {
      withCredentials: false
      },
      success: function(response){
      $('#res_data').val(response);
      }
      });
      });


      Tuned me if you not find this helpful .






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        May Be I understand your Question ! You want your success Response data to your Same page where this action took place



        First You have to create a dive with id <div id=res_data> </div> and place this div where you want to show your response data .



        Then Your Final code is



        document.getElementById("button1").addEventListener("click", function (e) {
        e.preventDefault();
        $.ajax({
        url: 'http://localhost:8080/someLoginUrl',
        method: 'GET',
        crossDomain : true,
        xhrFields: {
        withCredentials: false
        },
        success: function(response){
        $('#res_data').val(response);
        }
        });
        });


        Tuned me if you not find this helpful .






        share|improve this answer












        May Be I understand your Question ! You want your success Response data to your Same page where this action took place



        First You have to create a dive with id <div id=res_data> </div> and place this div where you want to show your response data .



        Then Your Final code is



        document.getElementById("button1").addEventListener("click", function (e) {
        e.preventDefault();
        $.ajax({
        url: 'http://localhost:8080/someLoginUrl',
        method: 'GET',
        crossDomain : true,
        xhrFields: {
        withCredentials: false
        },
        success: function(response){
        $('#res_data').val(response);
        }
        });
        });


        Tuned me if you not find this helpful .







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 7 at 11:17









        Afzal

        125




        125






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53188071%2fhow-do-i-modify-the-response-url-of-an-ajax-function%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini