我想显示用$.get()发送的完整请求

I want to display the complete request sent with $.get()

本文关键字:请求 显示 get      更新时间:2023-09-26

如何显示从$.get请求发送到服务器的完整请求,我的请求如下:

$.get("http://api.yelp.com/business_review_search", 
    { 
        'ywsid': xxxx', 
        'term': term, 
        'limit': 20, 
        'location': location, 
        'category': category
    }, function add(data, textStats, jqXHR) {----}}}, 'jsonp');

在这里,我想在网页上显示发送给服务器的确切请求。

jqXHR对象可能有完整的URL(带回调),如果这是你想要的,尽管我还没有找到它(你可能很幸运地浏览了这里http://api.jquery.com/jQuery.ajax/)。如果您不需要序列化的参数,请使用http://api.jquery.com/jQuery.param/.

var data = {
    'ywsid': 'xxxx',
    'term': term,
    'limit': 20,
    'location': location,
    'category': category
}
var url = "http://api.yelp.com/business_review_search"
doSomethingWith(url, data)
$.get(url, data, function add(data) {
  alert(this.url) // it might be this!
}, 'jsonp');
function doSomethingFancyWith(url, data) {
  var queryString = $.param(data)
  alert(url + "?" + data)
}

编辑:在成功函数中尝试this.url。它似乎在非json-p的情况下对我有效,这里也引用了它访问回调函数中jQuery Ajax请求的URL

使用Firebug。(mozilla的调试器)您将能够看到使用此工具发送的请求。

你可以用这样的东西打印出来。。

 For Each item In Request.Form
 Response.Write  Request.Form(item) & "<BR />" 
 Next 
$.get("yoururlcontainingtheabove",
 function(data)
{$("#div").html(data)}
,text);

如果您想显示发送到服务器的实际请求、头等等,则需要使用服务器端语言在处理请求之前捕获请求。

只有当您控制了向其发出请求的服务器时,这才有可能。否则,据我所知,这是不可能的。

您可以使用等调试工具

小提琴手

firebug

我也遇到过类似的问题,

我试图研究jquery javascript文件中的ajax函数。这个函数中有一个变量"s"。s.url将给出带有数据n参数的呼叫请求,

function success() {
        // If a local callback was specified, fire it and pass it the data
        if ( s.success ) {
            s.success.call( callbackContext, data, status, xhr );
        }
        // Fire the global callback
        if ( s.global ) {
            trigger( "ajaxSuccess", [xhr, s] );
        }
    }