views:

345

answers:

4

hey there :-)

Okay, i have a job to do before tomorrow morning..

i'm working on some jquery. Where i load some external file data..

What i really want to know, is how am i going to load some data when i $.post / or $.get some data through jquery

Send request into jquery <a href="javascript:;" onclick="$.view.load('prices');">hey </a>

and the same time change the url browser to ex. mywebsite.com/prices/ without making the refresh on the page

is it possible, and how to do ?

// edit (not working)

    <li><a href="/prices"  onclick="$.view.show('prices');"> <span>prices</span></a></li>

jquery: $('a.prices').click(function(e) {
            e.preventDefault();
            $.view.show('prices');
        });`

but can see that some of the others samples are not that easy to make it work..

+1  A: 

As far as I know, you can only change the url for the anchor part (www.url.com/#anchor), and nothing else (without a browser refresh). Perhaps you can use SWFAddress for your purposes?

nikc
+2  A: 

You can use a jQuery plugin called URL Utils - there's also a great screencast that shows you how to use it.

Andy Gaskell
+3  A: 

You can do it like this:

<a href="mywebsite.com/prices/" class="priceLink">hey</a>

$('a.priceLink').click(function(e) {
    e.preventDefault();
    $.view.load('prices');
});

When the user click the link, the normal URL will be shown on the browser line, but won't get visited (because of preventDefault) and $.view.load('prices'); will thus load in that content without refreshing the page.

EDIT: @William - please try this:

<li><a href="/prices" class="prices"><span>prices</span></a></li>

    $('a.prices').click(function(e) {
        e.preventDefault();
        $.view.show('prices');
    });
karim79
As a bonus, copied links will also work as expected.
nikc
...and those links are visitable if Javascript is off/unavailable.
karim79
its not working :-/ it just send me to an Not Found page... :(
william
@william - did you give your link the priceLink class as above? Can you paste what you have tried?
karim79
I changed text: below (// edit (not working))
william
@william - you're almost there, but you still have the onclick in the anchor tag which you need to get rid of, also you did not give it a class as per my example. I will edit.
karim79
A: 

i found the solution!!

http://nix.lv/history/demo.html

took me about 10min to install, and it just work perfectly..(i did some mod )

solution:

<li><a href="/prices" rel="history" class="prices"><span>prices</span></a></li>

jquery(download the plugin at the link above):

$.history.init(pageload); 

    // PageLoad function
 function pageload(hash) {

 // hash doesn't contain the first # character.
 if(hash) {
        $.view.show(hash); // load pages
 } else {
  // start page
        $.view.show(load_from_start);
 }
}

try it.. :)

william