tags:

views:

35

answers:

1
$.ajax({ type: "POST", url: "OMFG.php", data: info, success: function(){ }});

is what I'm using atm as a test and it works fine.

I need to get the url from the link I'm clicking, so I do:

var url = $(this).attr("href");

which works fine if I alert it out(the link includes http://samedomain.com/etc.php), but the ajax function doesn't post if I insert it into the ajax code:

$.ajax({ type: "POST", url: url, data: info, success: function(){ }});

Please help, as I'm screwed without this working.

A: 

You are using the id attribute. For getting the link you need to fetch the href attribute:

var url = $(this).attr('href');

EDIT: See you just changed to href - if that still does not work try debugging by using

alert($(this).attr('href'));

and see if it alerts an url and if it is correct.

EDIT 2: Well, check in firebug in FF or Javascript Console in Chrome for errors or what url the script really is trying to post to. Depending on the rest of the code your url-variable might be out of scope if it is defined within some function or something.

alexteg
sorry, I mistyped it when I was using doing the question, I am using href in my actual code. This is not the issue.
Kirill
The paragraph under it (right under it) states that it does, I have tried it again, just to double check, does work.
Kirill