如何在URL上发送AJAX请求?

时间:2021-11-13 07:13:35

Hi I am not sure if you guys will undestand me because I am spanish and I speak little english but I'll try it: I would like when user sends in URL browser like http://www.facebook.com/profile.php?id=000000001 the browser don't send a request to the server,and AJAX loads the content inside of a DIV. How can I make it work? I hope you can help me and undertand me. Thanks

嗨,我不确定你们是否会认出我来,因为我是西班牙人,我不会说英语,但我会试着:我希望当用户在http://www.facebook.com/profile.php?浏览器不会向服务器发送请求,而AJAX会加载DIV中的内容。我希望你能帮助我,安德和我。谢谢

4 个解决方案

#1


1  

The browser will always reload the page if you change the address. The Ajax way of handling page changes is to work with the hash tag, which is everything after the pound sign ( # )

如果您更改了地址,浏览器将始终重新加载页面。处理页面更改的Ajax方式是使用散列标记,它是在#之后的所有东西

www.example.com#page=one www.example.com#page=two www.example.com#page=three&more=params

www.example.com页面=一个www.example.com页面= = 3 =参数两个www.example.com页面

#2


1  

Thats a complex issue, you can ether use hashbangs ( http://www.facebook.com/profile.php#!000000001) because they don't force the browser to (re)load a page, but you can catch them via AJAX if the page is loaded. If you don't want to use hashbangs the HTML5 History Interface http://www.w3.org/TR/html5/history.html would be a Way to go, but its not supported by many browsers, but i made some working stuff under chrome.

这是一个复杂的问题,您可以使用hashbangs (http://www.facebook.com/profile.php#!000000001),因为它们不会强制浏览器加载页面,但是如果页面被加载,您可以通过AJAX捕获它们。如果你不想使用hashbangs HTML5 History接口http://www.w3.org/TR/html5/history.html将是一个不错的选择,但是它不被很多浏览器支持,但是我在chrome下做了一些工作。

#3


1  

You can use Fiddler to sniff the data sent to the server through AJAX, Then you can write HTTPWebRequest/Response to simulate it.

您可以使用Fiddler来嗅探通过AJAX发送到服务器的数据,然后您可以编写HTTPWebRequest/Response来模拟它。

#4


0  

You can use the GET on url with this function to make an Ajax call :

您可以使用这个函数的GET on url进行Ajax调用:

$.extend({
    getUrlVars: function(){
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for(var i = 0; i < hashes.length; i++){
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
        return vars;
    },
    getUrlVar: function(name){
        return $.getUrlVars()[name];
    }
});

And parse arguments :

和解析参数:

$(document).ready(function(){
    // load ajax call
    if( $.getUrlVar('param') != null ){
        $.ajax({
            data: {
                something_var: $.getUrlVar('param')
            },
            success: function(data){
              alert(data);
            }
        });
    }
});

Example url : http://www.website.com/?param=ok

示例url:http://www.website.com/?param=ok

Hope it's what you want :)

希望这就是你想要的

#1


1  

The browser will always reload the page if you change the address. The Ajax way of handling page changes is to work with the hash tag, which is everything after the pound sign ( # )

如果您更改了地址,浏览器将始终重新加载页面。处理页面更改的Ajax方式是使用散列标记,它是在#之后的所有东西

www.example.com#page=one www.example.com#page=two www.example.com#page=three&more=params

www.example.com页面=一个www.example.com页面= = 3 =参数两个www.example.com页面

#2


1  

Thats a complex issue, you can ether use hashbangs ( http://www.facebook.com/profile.php#!000000001) because they don't force the browser to (re)load a page, but you can catch them via AJAX if the page is loaded. If you don't want to use hashbangs the HTML5 History Interface http://www.w3.org/TR/html5/history.html would be a Way to go, but its not supported by many browsers, but i made some working stuff under chrome.

这是一个复杂的问题,您可以使用hashbangs (http://www.facebook.com/profile.php#!000000001),因为它们不会强制浏览器加载页面,但是如果页面被加载,您可以通过AJAX捕获它们。如果你不想使用hashbangs HTML5 History接口http://www.w3.org/TR/html5/history.html将是一个不错的选择,但是它不被很多浏览器支持,但是我在chrome下做了一些工作。

#3


1  

You can use Fiddler to sniff the data sent to the server through AJAX, Then you can write HTTPWebRequest/Response to simulate it.

您可以使用Fiddler来嗅探通过AJAX发送到服务器的数据,然后您可以编写HTTPWebRequest/Response来模拟它。

#4


0  

You can use the GET on url with this function to make an Ajax call :

您可以使用这个函数的GET on url进行Ajax调用:

$.extend({
    getUrlVars: function(){
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for(var i = 0; i < hashes.length; i++){
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
        return vars;
    },
    getUrlVar: function(name){
        return $.getUrlVars()[name];
    }
});

And parse arguments :

和解析参数:

$(document).ready(function(){
    // load ajax call
    if( $.getUrlVar('param') != null ){
        $.ajax({
            data: {
                something_var: $.getUrlVar('param')
            },
            success: function(data){
              alert(data);
            }
        });
    }
});

Example url : http://www.website.com/?param=ok

示例url:http://www.website.com/?param=ok

Hope it's what you want :)

希望这就是你想要的