Hi,

I believe you can use the following approach:

Since you are requesting to another page, you can use the server-side
script (PHP) to return the id, type, and success message in JSON
format and then use them from jQuery, and instead of $.get, you can
use $.getJSON or $.ajax, Using this approach would also allow you to
show an error message should any error occur in server side.

http://docs.jquery.com/Ajax/jQuery.getJSON
http://docs.jquery.com/Ajax/jQuery.ajax

Also,  just a thought, using class 'doit' instead of id would allow to
you assign it to multiple Tags/elements on the page.

[html]
<a href="something.php?id=123&type=456" class="doit" title="Do it">do
it</a>

<a href="something.php?id=788&type=457" class="doit" title="Do it">do
it</a>

[js]

$(".doit").click(function(){
   var $this = $(this);  // store this reference for future use
   $.getJSON(this.href, function(data) {
        if( data.success == '1') {
            //  successful from server-side
            $this.replaceWith('I\'ve been there (<a href="something.undo.php?
id='+data.id+'&type='+data.type+'">undo</a>)');
         }      else {
                // not successful, show error or do something else
         }
   });
        return false;
});

[php /server-side script]

// process the request and then IF Successful, then echo in JSON
format,
header('Content-Type: text/plain');
echo '{ success : "1" , id : "'.$_GET['id'].' ", type: ".$_GET
['type'].'" }';
// or you can use json_encode (requires PHP 5.2)
exit;


// PHP - json_encode,
http://ca.php.net/json_encode


There are several other alternative approach... I hope it helps,


Thanks,
Abdullah.

On Mar 30, 10:44 am, Peter Van Dijck <petervandi...@gmail.com> wrote:
> Hi all,I couldn't find a good answer to this, although it has probably been
> answered before, apologies!
>
> I have a link
> <a id="doit" href="/bla/something.php?id=123&type=456">do it</a>
>
> And some jQuery code
>
> $("#doit").click(function(){ // upon click
> $.get(this.href); // call the URL
> $('#doit').replaceWith("I've been there (<a
> href=/bla/something.undo.php?id=123&type=456'>undo</a>)");
> return false;
>  });
>
> My problem is that I want to populate the URL that's in "replaceWith" with
> the correct id, depending on the id that was in the original link. I've
> thought of using a fake attribute in the link somehow (<a type="456"
> id="doit"), but I can't seem to get it to work, and I'm not sure this is the
> right approach...
>
> What would be the jquery-like best way to do this?
>
> Thanks!
> Peter
>
> --
> me:http://petervandijck.com
> blog:http://poorbuthappy.com/ease/
> global UX consulting:http://290s.com
> free travel guides:http://poorbuthappy.com
> Belgium: (+32) 03/325 88 70
> Skype id: peterkevandijck

Reply via email to