对于想了解jquery–有没有更好的方法来检查AJAX请求的值是否有效?的读者,本文将是一篇不可错过的文章,我们将详细介绍检测ajax请求异常,并且为您提供关于java–有没有更好的方法来保持地图的值
对于想了解jquery – 有没有更好的方法来检查AJAX请求的值是否有效?的读者,本文将是一篇不可错过的文章,我们将详细介绍检测ajax请求异常,并且为您提供关于java – 有没有更好的方法来保持地图的值是一个集合?、javascript-是否有更好的方法根据通过jQuery的行数来选择表?、jQuery ajax请求有效,相同的AngularJS ajax请求无效、jquery – 有没有更好的方法来根据与Meteor.js反应的输入字段更新html?的有价值信息。
本文目录一览:- jquery – 有没有更好的方法来检查AJAX请求的值是否有效?(检测ajax请求异常)
- java – 有没有更好的方法来保持地图的值是一个集合?
- javascript-是否有更好的方法根据通过jQuery的行数来选择表?
- jQuery ajax请求有效,相同的AngularJS ajax请求无效
- jquery – 有没有更好的方法来根据与Meteor.js反应的输入字段更新html?
jquery – 有没有更好的方法来检查AJAX请求的值是否有效?(检测ajax请求异常)
@ajax_required def poll(request): try: last_id = int(request.POST.get('last_id')) Feed_type = request.POST['Feed_type'] except (KeyError,TypeError): return HttpResponseBadRequest() if Feed_type == 'following' and request.user.is_authenticated(): posts = Post.get_posts(user=request.user,after_id=last_id) return JsonResponse({ 'html': render_to_string('posts/raw_posts.html',{'posts': posts}),'count': posts.count() }) return HttpResponseForbidden()
正如你所看到的,我必须做很多样板并且沉默一些语言本身的例外,这涉及到我来自PHP背景.有没有更好的方法来做到这一点,还是我正确地做事?
解决方法
编辑:
如果您选择使用它,您的代码看起来会更像这样:
from rest_marshmallow import Schema,fields class FeedSchema(Schema): last_id = fields.Integer() Feed_type = fields.String() @ajax_required def poll(request): try: # Validate request serializer = FeedSchema(data=request.data) serializer.is_valid(raise_exception=True) data = serializer.validated_data # Return posts if data['Feed_type'] == 'following' and request.user.is_authenticated(): posts = Post.get_posts(user=request.user,after_id=data['last_id']) return JsonResponse({ 'html': render_to_string('posts/raw_posts.html','count': posts.count() }) # The user isn't authenticated or they requested a Feed type they don't have access to. return HttpResponseForbidden() except ValidationError as err: return HttpResponseBadRequest(err.messages)
java – 有没有更好的方法来保持地图的值是一个集合?
Mapping MultiMaps with Hibernate是一个似乎得到最多引用的东西,它详细描述了如何使用UserCollectionType实现它.
我想知道,既然是四年前写的,现在有没有更好的办法呢?
所以,例如,我想对EntityA做一个地图,Set / List< EntityB>>.
将有两个表:EntityA和EntityB(EntityB有一个外键返回EntityA).
我不想要任何中间表.
解决方法
public static String toXML(Object instance) { XStream xs = new XStream(); StringWriter writer = new StringWriter(); xs.marshal(instance,new CompactWriter(writer)); return writer.toString(); }
然后在休眠中使用Lob类型来持久化:
@Lob @Column(nullable = false) private String data;
我发现这种方法非常通用,您可以通过它有效地实现灵活的键/值存储.你不喜欢XML格式,那么Xstream框架有内置的将对象转换为JSON的驱动程序.试一试,真的很酷
干杯
编辑:回应评论.
是的,如果你想克服经典方法的限制,你可能会牺牲像索引和/或搜索那样的东西.您可以通过自己的集合/通用实体bean实现索引/搜索/外部/子关系 – 只需维护单独的键/值表,其中需要您想要搜索的属性名称/属性值.
我已经看到了需要灵活和动态的产品的数据库设计数量(即为没有停机时间的域对象创建新属性)模式,许多数据库设计使用键/值表来存储域属性和所有者对象的引用到子级.这些产品花费数百万美元(银行/电信),所以我猜这种设计已被证明是有效的.
对不起,这不是您的原始问题的答案,因为您询问没有中间表的解决方案.
javascript-是否有更好的方法根据通过jQuery的行数来选择表?
我正在寻找使用jQuery具有超过X行的一组表.目前,我正在做类似的事情:
$("table").each(function(){
if($(this).find("tr").length > x){
tableArray[tableArray.length] = $(this);
}
});
然后作用于tableArray的成员.
有没有更好的方法来获取这些表,也许我错过了一个不错的选择器?
谢谢
:has
选择器:
$('table:has(tr:eq('+x+'))');
那只会获取具有行x的表.注意:eq()
的参数从零开始,这意味着如果x为1,则将选择包含2行或更多行的表.
编辑::has为我倒下,:nth-child和:eq. .has()
(与选择器等效的方法)可以运行:
alert($('table').has("tr:nth-child(2)").length)
虽然,请注意传递给nth-child的参数不是基于零的,如:eq是.
Example-警报找到2行或更多行的表的数量.
jQuery ajax请求有效,相同的AngularJS ajax请求无效
我正在学习AngularJS,并尝试构建从Wordpress获取数据的前端系统。
在后端,一切似乎都已正确设置,当我使用jQuery ajax请求时,它可以毫无问题地获取数据。
jQuery.ajax({ type: ''POST'', url: ''/wp-admin/admin-ajax.php'', data: { action: ''getdataajax'' }, success: function(data, textStatus, XMLHttpRequest){ console.log(data); }, error: function(MLHttpRequest, textStatus, errorThrown){ console.log(errorThrown); }});
但是,当我尝试使用AngularJS做同样的事情时,它不起作用。我正在尝试使用以下代码复制ajax请求:
myApp.factory(''productsData'', function($http, $log) { return { getProducts: function(successcb) { return $http({ method: ''POST'', url: ''/wp-admin/admin-ajax.php'', data: {action: ''getdataajax''} }).success(function(data, status, headers, config) { successcb(data); $log.info(data, status, headers(), config) }).error(function(data, status, headers, config) { $log.warn(data, status, headers(), config) }); }, };});
如果我将其记录下来,它将输出0。我缺少什么?
谢谢你的帮助。
PS控制器如下所示:
myApp.controller(''ProductsController'', function ProductsController($scope, productsData) { $scope.sortorder = ''name''; // $scope.products = productsData.products; // $scope.products = productsData.getProducts(); productsData.getProducts(function(products){ $scope.products = products; });});
答案1
小编典典在angularjs代码中,使用params:
代替data:
。
在jquery中,data:
除非您设置,否则提供给config设置的对象将转换为查询字符串(?key1 = val1&key2 =
value2)processData:false
。在angularjs中,您必须用于params:
获取查询字符串,data:
以json或string的形式发送。
jquery – 有没有更好的方法来根据与Meteor.js反应的输入字段更新html?
我想在Meteor中重新创建这个功能,但效果不佳.首先,由于某种原因,它不会更新最后一个字母.使用Angular.js执行此演示视频也更容易,效果更好,有没有更好的方法在Meteor中执行此操作?
另外,如果有办法访问DOM而不是辅助函数?在事件函数中,我可以使用’t’变量来访问DOM,但是在helpers函数中我不知道如何,例如我是否想从helper函数中的div中获取文本.我不知道怎么做.
这是我的Meteor代码,这是一个现场演示:http://todotestapp.meteor.com
提前致谢
HTML
<head> <title>Todo</title> </head> <body> {{> hello}} </body> <template name="hello"> <input id="personName" type="text"> <h1>Hello {{personName}}!</h1> </template>
流星Javascript
if (Meteor.isClient) { Template.hello.helpers({ personName: function () { return Session.get("personName"); } }); Template.hello.events({ 'keypress #personName': function (e,t) { Session.set("personName",t.find("#personName").value); } }); }
解决方法
2)使用普通的jquery来获取值
所以:
Template.hello.events({ 'keyup #personName': function () { Session.set("personName",$("#personName").val()); } });
我们今天的关于jquery – 有没有更好的方法来检查AJAX请求的值是否有效?和检测ajax请求异常的分享已经告一段落,感谢您的关注,如果您想了解更多关于java – 有没有更好的方法来保持地图的值是一个集合?、javascript-是否有更好的方法根据通过jQuery的行数来选择表?、jQuery ajax请求有效,相同的AngularJS ajax请求无效、jquery – 有没有更好的方法来根据与Meteor.js反应的输入字段更新html?的相关信息,请在本站查询。
本文标签: