Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing variable from javascript to php (can it be done)? 1

Status
Not open for further replies.

JohnnyT

Programmer
Jul 18, 2001
167
GB
This is the function I want to execute:
function confirm_delete(comment_ID) {
<?php wp_delete_comment( $comment_id ) ?>
}

I need to get var comment_ID into $comment_id ??

Any ideas if this is possible?

Also can you just run php from within javascript like this?

Many thanks for any light you can shed on this

All the best

John ;-)

I don't make mistakes, I'm merely beta-testing life.
 
Hi

John said:
Passing variable from javascript to php (can it be done)?
Yes. Make a request and send the variable's value in a GET or POST parameter.

Sounds like you are thinking to something closer to AJAX. In which case see forum1600 .

Feherke.
 
Thanks for that. I've done it with a POST var as you suggested.

I'll have to look into AJAX. Not really got an idea what that's about ??

Cheers

John ;-)

I don't make mistakes, I'm merely beta-testing life.
 
Hi

John said:
I'll have to look into AJAX. Not really got an idea what that's about ??
Not a big deal.

Usually you are accessing an URL to see the document behind it. For this you
[ul]
[li]type in the URL into you browser's location/address bar[/li]
[li]press Enter.[/li]
[/ul]
And the browser
[ul]
[li]makes the request[/li]
[li]processes the received document.[/li]
[/ul]
If you want to access an URL to programmatically process the document behind it in your JavaScript code, you use AJAX. For this you
[ul]
[li]instantiate an [tt]XMLHttpRequest[/tt] object : [tt]http[teal]=[/teal]new XMLHttpRequest[teal]()[/teal][/tt][/li]
[li]set up the request : [tt]http[teal].[/teal]open[teal]([/teal][green]'GET'[/green][teal],[/teal][green]'[ignore][/ignore]'[/green][teal],[/teal]false[teal])[/teal][/tt][/li]
[li]send the request : [tt]http[teal].[/teal]send[teal]([/teal]null[teal])[/teal][/tt][/li]
[/ul]
And the [tt]XMLHttpRequest[/tt] object
[ul]
[li]makes the request[/li]
[li]communicates the status while working[/li]
[li]makes the result available in the given object : [tt]alert[teal]([/teal][green]'Server says : '[/green][teal]+[/teal]http[teal].[/teal]responseText[teal])[/teal][/tt][/li]
[/ul]
For a better explanation see the [tt]XMLHttpRequest[/tt] article on Wikipedia.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top