BlastWave
BlastWave

Reputation: 797

html object to call php and return string

I want to call a php script (with args) from HTML and to process the returned data I tried various flavours of :

<object id=test1 data="object.php" type="text/plain">

where object.php just returns a string, like

<?php print "firstText:Hello World";?>

I can't work out how to retrieve the returned string.
I was hoping to find it in something like

document.getElementById("test1").firstText
But no joy
Why am I doing this, you ask?
I'd like to get the page working interactively between the user and the server, avoiding the repainting of the browser window that comes with re-submitting with POST/GET.

Upvotes: 0

Views: 355

Answers (3)

BlastWave
BlastWave

Reputation: 797

Thanks for your responses. I'm not happy using JQuery - another layer beyond my control I have eventually found the returned text in

document.getElementById("test1").contentDocument.body.firstChild.textContent

which I can then work with. Thanks

Upvotes: 1

Markus013
Markus013

Reputation: 72

PaulPros idea is probably your best method. Don't forget to include jQuery.

Is there any reason you could not just make the .HTML a .php file and include your script?

Upvotes: 0

Paul
Paul

Reputation: 141877

Use AJAX. Here's an example using jQuery:

$.get('yourpage.php', function(response){
    // response contains the string returned by your PHP page.
});

Upvotes: 0

Related Questions