Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法从JSON获取URL,当我尝试时,它显示未定义。有什么建议吗?_Javascript_Jquery_Html_Json - Fatal编程技术网

Javascript 无法从JSON获取URL,当我尝试时,它显示未定义。有什么建议吗?

Javascript 无法从JSON获取URL,当我尝试时,它显示未定义。有什么建议吗?,javascript,jquery,html,json,Javascript,Jquery,Html,Json,无法从JSON获取URL,当我尝试时,它显示的是未定义的。有什么建议吗 <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" ></meta> <script language="JavaScript" type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min

无法从JSON获取URL,当我尝试时,它显示的是
未定义的
。有什么建议吗

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" ></meta>
<script language="JavaScript" type="text/javascript"  src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>

function a()
{
$.getJSON("https://tbe.taleo.net/MANAGER/dispatcher/api/v1/serviceUrl/UDAY",function(data) { alert(JSON.stringify(data));});
}
</script>
</head>
<body>
<input type="button" value="GET JSON" onclick="a()"/>
</body>
</html>
有更好的方法吗?我并没有把函数作为变量声明使用,所以我应该在花括号后面用分号吗?我的意思是在函数声明后面

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" ></meta>
<script language="JavaScript" type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
window.onload = function a(){
$.getJSON("https://tbe.taleo.net/MANAGER/dispatcher/api/v1/serviceUrl/UDAY",function(data) {  
            var innerHtml = "";
            document.getElementById("CWS_URL").href=(data.response.URL).substr(0,(data.response.URL).indexOf("ats"))+"ats/careers/jobSearch.jsp?cws=1&org=UDAY";
            });
}
</script>
</head>
<body>
<a href="#" id ="CWS_URL" >Careers</a>
</body>
</html>

window.onload=函数a(){
$.getJSON(“https://tbe.taleo.net/MANAGER/dispatcher/api/v1/serviceUrl/UDAY“,函数(数据){
var innerHtml=“”;
document.getElementById(“CWS_URL”).href=(data.response.URL).substr(0,(data.response.URL).indexOf(“ats”)+“ats/careers/jobSearch.jsp?CWS=1&org=UDAY”;
});
}
完整样本:

<script src="https://code.jquery.com/jquery-2.2.3.min.js" type="text/javascript"></script>
<script type="text/javascript">

    $(function() {

        $('#btn').click(function() {

            $.getJSON(
                'https://tbe.taleo.net/MANAGER/dispatcher/api/v1/serviceUrl/CODE',
                function(data) {

                    alert(data.response.URL);
                }
            );
        });
    });  

</script>
<input type="button" id="btn" value="Get JSON">

$(函数(){
$('#btn')。单击(函数(){
$.getJSON(
'https://tbe.taleo.net/MANAGER/dispatcher/api/v1/serviceUrl/CODE',
功能(数据){
警报(data.response.URL);
}
);
});
});  
结果:


当jQuery可用时,不要使用纯JavaScript的事件指令。例如:
onclick=“a()”
。将其从HTML代码中删除。

getJSON
的回调中,
警报(data.response.URL)
显示了什么
未定义的
?您的代码示例可以正常工作,但您没有解释您尝试了什么,因此很难解释您错误地做了什么以及如何修复它。解释为什么应该删除HTML属性很有帮助。。。看见
<script src="https://code.jquery.com/jquery-2.2.3.min.js" type="text/javascript"></script>
<script type="text/javascript">

    $(function() {

        $('#btn').click(function() {

            $.getJSON(
                'https://tbe.taleo.net/MANAGER/dispatcher/api/v1/serviceUrl/CODE',
                function(data) {

                    alert(data.response.URL);
                }
            );
        });
    });  

</script>
<input type="button" id="btn" value="Get JSON">