使用jQuery和链接操作DOM元素(Manipulating DOM elements with jQuery and chaining)
玩jQuery有点(对不起,完全noob)我想知道为什么这不起作用。 也许我没有获得链接,上下文和DOM操作的方式,但我只是好奇。 这里是:
$("#myDiv") .append("h3") .append("a") .attr("href", "http://example.com") .text("Click here") .end();
我希望发生的事情是:
- 选择
#myDiv
- 在里面插入一个H3
- 然后在H3里面插入一个A标签
- 将A标签的HREF属性设置为一个URL
- 然后将A标签的文本设置为“Click Here”
相反,我的页面的标记似乎完全搞砸了,虽然我看不到动态DOM,所以我不知道发生了什么。 我读的jQuery文档错了吗?
Playing around with jQuery a bit (sorry, complete noob) I was wondering why this does not work. Maybe I'm not getting the way chaining, context and DOM manipulation works, but I'm just curious. Here it goes:
$("#myDiv") .append("h3") .append("a") .attr("href", "http://example.com") .text("Click here") .end();
What I would expect to happen:
- Select
#myDiv
- Insert an H3 inside it
- Then inside the H3, insert an A tag
- Set the A tag's HREF attribute to a URL
- And then set the A tag's text to "Click Here"
Instead my page's markup seems to get completely screwed up, although I can't see the dynamic DOM so I'm not sure what's happening. Am I reading the jQuery documentation wrong?
原文:https://stackoverflow.com/questions/6298048
最满意答案
请尝试以下方法:
如果你的响应是在json中,那么以下面的方式使用你的代码,然后在
doInBackground(Void... params)
使用你的'response'doInBackground(Void... params)
:DefaultHttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(serviceURL); request.setHeader("Accept", "application/json"); request.setHeader("Content-type", "application/json"); HttpResponse response = client.execute(request); HttpEntity entity = response.getEntity();
回复错误你得到的结果..
Try the following :
Use your code in the following manner if your response is in json and then use your 'response' from entity in
doInBackground(Void... params)
:DefaultHttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(serviceURL); request.setHeader("Accept", "application/json"); request.setHeader("Content-type", "application/json"); HttpResponse response = client.execute(request); HttpEntity entity = response.getEntity();
Reply with error what you result you get..
相关问答
更多-
HttpPost无法正常工作!(HttpPost not working!)[2022-02-12]
尝试这个: url = "http://10.0.218.211/post.php"; HttpClient httpclient = new DefaultHttpClient(); HttpPost post = new HttpPost(url); try { **// Add your data <-** ListnameValuePairs = new ArrayList (2); ... -
您可以按如下方式打印所有请求详情: HttpPost post = new HttpPost(); post.getAllHeaders(); post.getMethod(); // Post or get request post.getParams(); // Returns params post.getURI(); // Current Uri called 一旦得到回复, response.getAllHeaders(); httpRe ...
-
httpPost方法(httpPost Method)[2022-01-02]
您可以创建StringEntity ,将其设置为HttpPost对象,并设置正确的Content-Type : StringEntity entity = new StringEntity("data=" + java.net.URLEncoder.encode(body, "utf-8")); entity.setContentType("application/x-www-form-urlencoded"); httpPost.setEntity(entity); 然后像往常一样发送你的POST请求。 ... -
HttpPost - url vs params中的Params作为名称对(HttpPost - Params in url vs params as namevalue pair)[2022-02-12]
那么HTTP请求有所不同。 在第一个示例中,您使用给定的URL和空体发送HTTP请求。 第二,发送带有较短URL但带有参数的body的HTTP请求。 如果服务器上存在不同的行为,则取决于服务器(或它使用的框架)如何处理此类请求。 如果您想在HTTP级别上看到差异,请使用一些工具来检查输入和输出数据包(请求),例如Wireshark。 Well there is a difference in the HTTP request. In first example, you send HTTP request ... -
请尝试以下方法: 如果你的响应是在json中,那么以下面的方式使用你的代码,然后在doInBackground(Void... params)使用你的'response' doInBackground(Void... params) : DefaultHttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(serviceURL); request ...
-
检索从HttpPost传递到HttpGet的视图中的值(Retrieving a value in a view that is passed from HttpPost to HttpGet)[2022-06-20]
尝试在TempData中设置值并在验证操作中访问它并将其传递给验证视图,现在您可以在验证视图中访问故障Ticket模型。 TempData被持久化以用于后续请求。 RedirectToAction infact向浏览器发出302请求,然后重定向到Verify操作,您将从那里获取TempData的ticket 。 [HttpPost] public ActionResult Create(Ticket ticket) { TempData["ticket"] = ticket; return ... -
Httppost mysql是空的(Httppost mysql is empty)[2023-10-28]
如评论中所述,帖子正文应编码为UTF_8。 As posted in the comments, the post body should have been encoded as UTF_8. -
这个检查 if( response.getEntity().getContentLength() > 0) 是不正确的。 http header ContentLength可以设置为0. rfc不强制指定正确的大小。 您应该检查http请求的响应代码。 检查应该是: if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) 然后尝试阅读回复的内容。 通过rfc HTTP 200 request ok , HTTP 204为Req ...
-
HttpPost中的边界(Boundary In HttpPost)[2022-04-12]
边界是划分消息的各个部分。 除了图像或其他二进制数据之外,我还用它来返回一些XML。 我正在进行视觉分析,并且除了车辆图像之外还会返回跟踪记录(xml或json)。 我也用它来传输相机校准。 校准结构的各个部分作为xml / json / etc在一个区域中发送,而在另一个区域中是将每个像素映射到其真实世界位置(纬度,长度,高度)的二进制表。 没有边界,它假定整个响应是同构的(或用户解析)。 你提供了一个例子。 根据您设置的服务器/客户端,可以使用POST将其设置为服务器,也可以使用GET从服务器返回。 T ... -
我找到了解决方案。 将拦截器添加到客户端,我可以在执行之前获得包含所有头的完整请求,因此我不需要处理实体添加头的特殊情况。 HttpClientBuilder builder = HttpClientBuilder.create(); builder = builder.disableContentCompression().disableConnectionState(); builder.addInterceptorLast((HttpRequestInterceptor) (request, con ...