Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.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
Html 谷歌搜索框不工作,没有控制台错误_Html_Ajax_Jquery - Fatal编程技术网

Html 谷歌搜索框不工作,没有控制台错误

Html 谷歌搜索框不工作,没有控制台错误,html,ajax,jquery,Html,Ajax,Jquery,我正在练习编写jQuery和Ajax代码,并制作一个简单的Google搜索框,但它不起作用。没有控制台错误,Chrome中的调试也没有多大帮助。代码如下: <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Insert title here</title> <script type="text/javascript" src="ht

我正在练习编写jQuery和Ajax代码,并制作一个简单的Google搜索框,但它不起作用。没有控制台错误,Chrome中的调试也没有多大帮助。代码如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript"
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">

</script>
<script type="text/javascript">
    $(document).ready(function() {
        $("#button").click(function() {
            $.ajax({
                url : "http://www.google.com/search",
                dataType : "html",
                success : function(data) {
                    $("#show").html(data)
                },
                fail : function() {
                    alert("failed lol")
                }
            })
        })
    })
</script>
</head>
<body>
    <div id="search">
        <form name="input" method="get">
            Google it: <input type="text" name="googleit" /> <br /> <br /> <input
                id="button" type="button" value="let me google that for you" />
        </form>
    </div>
    <div id="show"></div>
</body>
</html>

在此处插入标题
$(文档).ready(函数(){
$(“#按钮”)。单击(函数(){
$.ajax({
url:“http://www.google.com/search",
数据类型:“html”,
成功:功能(数据){
$(“#show”).html(数据)
},
失败:函数(){
警报(“失败的lol”)
}
})
})
})
谷歌it:


这段代码有什么问题吗?

您不能那么容易地进行跨域调用,它受到限制。检查您的网络选项卡,它应该表明请求失败

此外,您甚至没有交出输入字段的值。您应该像这样将其附加到url
?q=hello

        $.ajax({
            url : "http://www.google.com/search?q=" + $("input").val(),
            dataType : "html",
你需要一个所谓的访问其他域


如果您实际请求的是更具体的页面,请查看.

,使用实际数据而不是重定向,例如
http://www.google.com/search?q=hello
然后您将看到交叉原点错误。