I have the following jQuery get request, which returns html text under the key name "data":

我有以下jQuery get请求,它返回键名“data”下的html文本:

$(".article").click(function() {
  $.get("<%= click_path %>", function(data) {
    $(".article").html(data);
  });
});

All the code executes except the line $(".article").html(data);. In fact, any jquery code I put inside the get request fails to execute, even though it all works fine if I move it outside the get request. Does anyone see anything wrong with my syntax?

所有代码都执行,除了行$(“。article”)。html(data);.实际上,我在get请求中放入的任何jquery代码都无法执行,即使它在get请求之外移动它都可以正常工作。有没有人看到我的语法有什么问题?

2 个解决方案

#1


1

jQuery's $.get method is an alias to $.ajax with an assumed HTTP request method of GET and without the ability to specify many options. You give it a URL and a function to run on successfully retrieving that URL. It tries to GET that URL and, if it can, the success function will run. If it can't, or if something is wrong with the response data, it fails silently and will not run the given function.

jQuery的$ .get方法是$ .ajax的别名,带有假定的GET HTTP请求方法,并且无法指定许多选项。您可以为其提供URL和函数,以便在成功检索该URL时运行。它尝试获取该URL,如果可以,将运行成功函数。如果它不能,或者响应数据出现问题,它将无声地失败并且不会运行给定的函数。

That being the case, I would assume your request is failing somewhere.

既然如此,我会假设您的请求在某处失败了。

You need to look in the developer's console for errors and to inspect the request.

您需要查看开发人员的控制台中的错误并检查请求。

You can also change your code to use $.ajax and pass in the options, along with your current params, an error method. If the error method is called, you'll receive as params the jqXHR instance, a string textStatus, and a string errorThrown. Pass these into console.log and look at them for clues as to what is wrong as well.

您还可以更改代码以使用$ .ajax并传递选项以及当前的参数,这是一种错误方法。如果调用了error方法,你将收到jqXHR实例,字符串textStatus和字符串errorThrown作为参数。将这些传递到console.log并查看它们以找出错误的线索。

$(".article").click(function() {
    $.ajax({
        url: "<%= click_path %>",
        success: function(data) {
            $(".article").html(data);
        },
        error: function (jqXHR, textStatus, errorThrown) {
            console.log(textStatus);
            console.log(errorThrown);
        }
    });
});

更多相关文章

  1. 如何使用ajax GET或POST方法将数据传递到amazon lambda节点。js
  2. 在each()函数内部调用多个ajax ..然后在完成所有这些操作后执行某
  3. Jquery常用技巧和方法收集
  4. Chosen 基于jquery的选择框插件使用方法
  5. 加载函数加载页面但不能对数据执行任何操作
  6. jQuery $ajax 传中文数据到action乱码解决方法
  7. JQuery 的选取元素 和 方法
  8. 绑定和解除相同javascript函数的目的是什么?
  9. jquery的function方法中each循环里面判断失败跳出function方法

随机推荐

  1. 【原创】Android 耗电信息统计服务——Ba
  2. android mms流播放器
  3. android 判断是否支持闪光灯
  4. Android中C/C++的日志打印
  5. OMS:拥有Android血统的智能操作系统王
  6. Android中的异步消息处理机制Hander
  7. Android上的Back键事件捕获
  8. 如何判断用户用的是Android手机还是IOS手
  9. 2017 年 Android 领域大事件回顾
  10. Android自定义视图四:定制onMeasure强制显