检测请求是否是jQuery中的帖子 [英] detecting if a request is a post in jQuery

查看:81
本文介绍了检测请求是否是jQuery中的帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以不同的方式加载页面,如果它是帖子或获取,并且看起来像jQuery会有一些东西,所以我可以做

I'm trying to load a page differently if it is a post or a get, and seems like jQuery would have something so I could do

    if (isPost()) 
    { 
      // do something if this page was a post 
    }

我根据请求类型显示/隐藏某些内容,并希望专门使用javascript进行操作。我可以轻松地使用我正在使用的框架,但不想这样做。

I'm showing/hiding something based on the request type and want to do it specifically with javascript. I can easily do it with the framework I'm using, but don't want to.

推荐答案

这里的问题是你在客户端与服务器端混淆。

The problem here is that you are confusing client-side with server-side.

GET,POST,PUT,DELETE等都是从客户端发送到服务器的HTTP'方法' (例如:浏览器)。然后,服务器以适当的HTTP响应进行响应,通常采用包含HTML的内容形式。

GET, POST, PUT, DELETE, etc are all HTTP 'methods' that are sent to a server from the client (e.g.: the browser). The server then responds with the appropriate HTTP response, normally in the form of content that contains HTML.

POST / GET / etc在客户端没有上下文指令如何将请求发送到服务器。

POST/GET/etc have no context at the client side outside of dictating how a request should be sent to the server.

将浏览器视为您的邮政邮箱,并将POST / GET /等作为传递方式。当有人向您发送一封邮件时,他们会指定方法,例如头等邮件,隔夜快递或当天发送。邮局根据邮件收到的方式处理邮件,并使用适当的操作发送邮件。当您在邮箱中接收邮件时,您不知道它是通过标准邮件,隔夜快递还是当天发送来到达的。您知道的唯一方法是信封本身的任何信息。

Think of the browser being your postal mailbox and POST/GET/etc being the method it was delivered. When someone sends you a piece of mail, they specify the method, such as first-class mail, overnight express, or same-day delivery. The Post Office handles the mail based on how it was received and sends the mail using the appropriate action. When you pick up your mail in the mailbox, you don't know if it got there via standard mail, overnight express, or same-day delivery. The only way you would know is any information that is on the envelope itself.

您的问题的解决方案将遵循相同的原则。要解决它,你需要做的是包含一个jQuery可以引入的隐藏值,可以是查询字符串,特殊元素,也可以是包含用于获取页面的HTTP方法的隐藏文本框。

The solution to your problem would would follow this same principal. To resolve it, what you will need to do is include a hidden value that jQuery can pull in, either in the query-string, a special element, or as a hidden textbox that contains the HTTP method used to get the page.

这需要相应地更改服务器端代码以将该信息推送回客户端。

This requires that server-side code be changed accordingly to push that information back to the client.

希望有帮助把它清理一下。

Hope that helps clear it up a bit.

这篇关于检测请求是否是jQuery中的帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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