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.
javascript jquery ajax
add a comment |
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.
javascript jquery ajax
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
add a comment |
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.
javascript jquery ajax
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
javascript jquery ajax
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
add a comment |
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
add a comment |
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 .
add a comment |
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 .
add a comment |
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 .
add a comment |
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 .
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 .
answered Nov 7 at 11:17
Afzal
125
125
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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