简体   繁体   English

在React中,如何从URL获得响应。 注意:-URL命中不是ajax命中

[英]In React how to get response from URL. Note:- URL hit is not an ajax hit

onButtonClick= (authLink) => {

            if(authLink){
                window.open(authLink, '_blank');
            }
     };

response from this url is :- 这个网址的回应是:-

{
"statusCode":"STATUS_OK",
"statusMessage":"The operation was successful.",
"statusUserMessage":"The operation was successful.",
"authToken":"AJFCNA",
"opaqueData":
    {"accessToken":"SJD.skb.zV-sdb-kajsb-dkjbc"},
     "authTokenValidity":21600,
    }
}

How to get this response in my code, I want to get the value for the key authToken . 如何在我的代码中获取此响应,我想获取键authToken的值。 I have no idea. 我不知道。 what can I do for this ? 我该怎么办?

I'm not sure what do you mean by "URL hit is not an ajax hit". 我不确定“ URL hit不是ajax hit”是什么意思。 You should be able to get the data using AJAX: 您应该能够使用AJAX获取数据:

fetch(authLink)
  .then(response => response.json())
  .then(data => { console.log(data.authToken) })
  .catch(err => { console.error(err) })

If for some reason you can't / don't want to use AJAX, and really need to call window.open() , you can check some interesting answers here: How to get element and html from window.open js function with jquery 如果由于某种原因您不能/不想使用AJAX,并且确实需要调用window.open() ,则可以在此处检查一些有趣的答案: 如何使用jquery从window.open js函数获取元素和html。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM