如何在jQuery $ .get / ajax请求中获取请求URL [英] How to get request url in a jQuery $.get/ajax request

查看:1819
本文介绍了如何在jQuery $ .get / ajax请求中获取请求URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

$.get('http://www.example.org', {a:1,b:2,c:3}, function(xml) {}, 'xml');

有没有办法在请求完成后获取用于发出请求的URL(在回调或其他方式)?

Is there a way to fetch the url used to make the request after the request has been made (in the callback or otherwise)?

我想要输出:

http://www.example.org?a=1&b=2&c=3


推荐答案

我无法让它在 $。get()上工作,因为它没有完成 event。

I can't get it to work on $.get() because it has no complete event.

我建议使用 $。ajax()这样,

$.ajax({
    url: 'http://www.example.org',
    data: {'a':1,'b':2,'c':3},
    dataType: 'xml',
    complete : function(){
        alert(this.url)
    },
    success: function(xml){
    }
});

这篇关于如何在jQuery $ .get / ajax请求中获取请求URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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