javascript - jQuery 获取 HTTP URL 请求

标签 javascript jquery ajax get httprequest

我最近尝试使用 jQuery 从 URL 获取一些响应。因此,我复制了 jQuery API Get Request Tutorial 的获取请求示例进入我的项目并尝试运行它,但我的调试消息告诉我,它无法继续运行。我使用一个简单的请求尝试了 javascript Ajax 库,但没有成功。

所以我问你,你是否能以某种方式帮助我。

这就是我所做的一切,但没有任何回应。

var url = "http://www.google.com";

$.get(url, function(data){


    alert("Data Loaded: " + data);
    });

我是否可能忘记包含 ajax 或 jQuery 库。为了更好地理解,我有 c 和 obj-c 经验,这就是我认为缺少库的原因。

在每个示例中,只有一个简短的 url,如“test.php”。我的完整 HTTP 网址是否有误?

感谢您提前回答。

Br 尼克

最佳答案

我提供了一个示例场景来帮助您入门:

<!-- Include this jQuery library in your HTML somewhere: -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script

这可能最好包含在外部 JS 文件中:

//Listen when a button, with a class of "myButton", is clicked
//You can use any jQuery/JavaScript event that you'd like to trigger the call
$('.myButton').click(function() {
//Send the AJAX call to the server
  $.ajax({
  //The URL to process the request
    'url' : 'page.php',
  //The type of request, also known as the "method" in HTML forms
  //Can be 'GET' or 'POST'
    'type' : 'GET',
  //Any post-data/get-data parameters
  //This is optional
    'data' : {
      'paramater1' : 'value',
      'parameter2' : 'another value'
    },
  //The response from the server
    'success' : function(data) {
    //You can use any jQuery/JavaScript here!!!
      if (data == "success") {
        alert('request sent!');
      }
    }
  });
});

关于javascript - jQuery 获取 HTTP URL 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5942105/

相关文章:

javascript - 根据字符串长度使用纯 JavaScript 调整字体大小

javascript - 为什么在浏览器中打开网页时功能不执行?

javascript - 如何在 ajax 上使用 this.children

javascript - 如何最好地修复 Chrome 数据列表渲染

javascript - 使用 AJAX 将数组传递给 PHP 文件

javascript - 向现有 MongoDB 文档添加一个字段(在 Node.js 中使用 Mongoose)

javascript - 嵌套 While 循环

c# - Azure Ad 身份验证不适用于带有 Angular 5.2 新模板的新 asp.net core 2.1。因为我们没有在新模板中路由到家庭 Controller

javascript - jQuery.ajax *仅*检索状态代码但不检索/下载整个文档?

c# - 如何将表单数据发送到 Controller 以发出 ajax 请求以将数据保存在 Db 中