jQuery 获取 HTTP URL 上的请求 [英] jQuery Get Request on HTTP URL

查看:13
本文介绍了jQuery 获取 HTTP URL 上的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近尝试使用 jQuery 从 URL 获取一些响应.因此,我将 jQuery API Get Request Tutorial 的获取请求示例复制到我的项目中并尝试运行它,但我的调试消息告诉我,它不能更进一步.我使用一个简单的请求尝试了 javascript Ajax 库,但没有奏效.

i've recently tried to get some Response from an URL using jQuery. Therefore I copied a get request sample of jQuery API Get Request Tutorial into my project and tried to run it, but my debugging messages showed me, that it can't go further. I tried the javascript Ajax Library using a simple request, but it didn't work.

所以我问你,如果你能以某种方式帮助我.

So i'm asking you, if you could help me somehow.

这就是我所做的一切,但没有回应.

And this is all what i do, but there is no response.

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

$.get(url, function(data){


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

我是否可能忘记包含 ajax 或 jQuery 库.为了更好地理解,我有 c 和 obj-c 经验,这就是为什么我认为缺少一个库.

Did i probably forgot to include a ajax or jQuery library. For a better understanding, i have c and obj-c experince, this is why i think, that a library is missing.

在每个示例中,只有一个像test.php"这样的短网址.我的完整 HTTP url 是错误的吗?

In each sample there is just a short url like "test.php". Is my complete HTTP url wrong?

感谢您提前回答.

溴网卡

推荐答案

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

I have provided an example scenario to help get you started:

<!-- 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 文件中:

This is probably best to include inside of an external JS file:

//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!');
      }
    }
  });
});

这篇关于jQuery 获取 HTTP URL 上的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆