jQuery应AJAX请求同时发送GET和POST参数 [英] jQuery send GET and POST parameters simultaneously at AJAX request

查看:517
本文介绍了jQuery应AJAX请求同时发送GET和POST参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过jQuery AJAX请求同时发送GET和POST参数?

How to send GET and POST parameters with jQuery AJAX request simultaneously?

我试图将do=ajax&id=" + ID添加到url,但是结果请求仅被磨砂到sss.php,而没有查询字符串(获取部分).谢谢.

I am trying to add do=ajax&id=" + ID to url, but as the result request sanded only to sss.php without query string (get part). thanks.

$.ajax({
    url: "sss.php?do=ajax&id=" + ID ,
    type: "post",
    data: "ddd=sss",
    // callback handler that will be called on success
    success: function(response, textStatus, jqXHR){
        // log a message to the console
        console.log("Hooray, it worked!");
    },
    // callback handler that will be called on error
    error: function(jqXHR, textStatus, errorThrown){
        // log the error to the console
        console.log(
            "The following error occured: "+
            textStatus, errorThrown
        );
    }
});

推荐答案

我认为您遇到了观察性错误,或者看到了服务器端而不是jQuery的问题.当我发帖时像这样:

I think you're getting an observational error, or seeing a server-side rather than jQuery problem. When I do a post like this:

$.ajax({
  url: "http://jsbin.com/eduzif/1?foo=bar",
  type: "post",
  data: "baz=doh",
  success: function() {
    display("Done, look at your console's network tab");
  }
});

...查询字符串和POST数据都发送到服务器.如果您使用类似Chrome或Firefox的现代浏览器,并在触发信息后查看控制台的网络"标签,则很容易进行检查.就我而言:

...both the query string and POST data are sent to the server. It's easy to check this if you use a modern browser like Chrome or Firefox and look in the Network tab of the console after triggering the post. In my case:

(您可以忽略上面的服务器回答403; JSBin不允许POST,但这不会影响我们在发送到服务器的请求中看到的内容.)

因此,这里的答案是:仔细检查如何获取数据服务器端. URL中的参数("GET"样式参数)可用作查询字符串参数(URL的一部分); "POST"样式参数可用作表单"数据(例如响应的正文).根据所使用的服务器端技术,通常有不同的方法来检索GET(查询字符串)参数与POST(表单数据/正文)参数.

So the answer here is: Double-check how you're getting the data server-side. The parameters in the URL ("GET" style parameters) are available as query string parameters (part of the URL); the "POST" style parameters are available as "form" data (e.g., the body of the response). Depending on the server-side technology you're using, usually there are different ways to retrieve GET (query string) parameters vs. POST (form data / body) parameters.

这篇关于jQuery应AJAX请求同时发送GET和POST参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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