2

I have a js file, containing a folder myFunc(phone_number)

Now when this js function is called, I want to make a POST request to the URI https://pay.something.in:443/FetchPhone/ passing the json {'phone_number' : 10 digit phone no. } as input to the request

and show its output in a new window.

Can somebody tell me how do I do that?

Sanjiban Bairagya
  • 704
  • 2
  • 12
  • 33
  • 1
    what have you tried? just blindly ask a question here doesn't helpful, you can just google how to make a post request in js and how to open new window – Sean Nov 07 '15 at 15:32
  • This might be related: https://stackoverflow.com/questions/24776180/xmlhttprequest-post-and-open-target-page-in-new-window-tab – David Nov 17 '17 at 02:03

1 Answers1

2

Seems to me like you want to make a POST request with xhr.

var xhr = new XMLHttpRequest();
xhr.open('POST', "https://pay.something.in:443")
xhr.setRequestHeader("Content-type", "application/json");
xhr.send( '{"phone_number" : 4455566677 }' );

xhr.onreadystatechange = function(){
    if (xhr.readyState != 4) return;
    if (xhr.status != 200 && xhr.status != 304) {
        alert('HTTP error ' + req.status);
        return;
    }

    console.log(xhr.responseText);//this is your response
    window.sessionStorage['response'] = xhr.responseText;
    window.open('Your window');//The data is accessible through sessionStorage.
}
Olavi Sau
  • 1,647
  • 13
  • 20