1

I am just a beginner in Web Development. But I got encountered with a interesting problem here we go.

Problem statement:

When I click on the Paragraph tag, I am making an Ajax call and it is opening in a new window, but the response i am getting from that called URL is not getting alerted in my current window. And also i wanted to close the ajax called window. I have Simplesaml authentication code in Filename.php

My code is as below Login.html:

<p>SSO</p>

Ajax call:

$('p').on("click", function(){
var newWindow = window.open("https://example.com/Filename.php", "new window", "width=400, height=500");
$.ajax({
        url: newWindow,
        async:false,
        success: function(res){  
        alert(res);
        console.log(res);     
        newWindow.close(); 
       }
    });
 })
2
  • window open has nothing to do with Ajax call, not sure where you learned that from. Commented Jun 27, 2018 at 13:19
  • newWindow is not an url Commented Jun 27, 2018 at 13:39

1 Answer 1

1

You need to use the url string in the url property of your AJAX call. Like this:

$.ajax({
        url: "https://example.com/Filename.php",
        async:false,
        success: function(res){  
        alert(res);
        console.log(res);     
        newWindow.close(); 
       }
    });
 })

https://developer.mozilla.org/en-US/docs/Web/API/Window/open

Sign up to request clarification or add additional context in comments.

3 Comments

window.open() returns a Window object which can't be used by AJAX as the url.
Thank you Álvaro Tihanyi, But i wanted that to open in a new window. And i should get that response in alert and close that window.
I don't know why do you want to open the new window and then close it but you could open the new window as you are doing right now, make the ajax request using the URL and close the new window on success.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.