Jump to content

Archived

This topic is now archived and is closed to further replies.

Rushyo

Loading two scripts simultaneously

Recommended Posts

I've got an AJAX engine which sends through an XML document to a PHP script, which then parses it into a set of urls like below:

loadpage.php?example=bleh
loadmenu.php?example=poot

Now, to the important bit... how can I load up more than one url at a time? I want to run loadpage.php and loadmenu.php and get them both to send data back to the client. I'm not asking for an 'alternative' method I simply need to know how to do this, if it is possible.

One plausible method is if PHP allows you to send HTTP requests to both pages... like so:

MakeRequest("loadpage.php?example=bleh");
MakeRequest("loadmenu.php?example=poot");

Obviously I can't use the header() function since I need to load two scripst from one script... and I can't change the header twice.

NOTE: My server using PHP 4.

Share this post


Link to post
Share on other sites
I think you can do it only 1 by 1 (PHP is not multi-threaded, is it?). But maybe Im wrong.
If you want to do it it 1 by 1, then use include or require.

Share this post


Link to post
Share on other sites
that only includes it, it doesn't give it a whole new set of POST/GET data to work with.

I was thinking something along the lines of CURL... but that might actually be available on my shared hosting.

Share this post


Link to post
Share on other sites
You can, I did it before, just include(loadmenu.php?example=poot);
If you want to pass by POST then you can use curl
[code]
// SET URL FOR THE POST FORM LOGIN
        curl_setopt($ch, CURLOPT_URL, 'linkkkkk');
        
        // ENABLE HTTP POST
        curl_setopt ($ch, CURLOPT_POST, 1);
        
        // SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
        curl_setopt ($ch, CURLOPT_POSTFIELDS, "login=something&password=somwthing);[/code]

Share this post


Link to post
Share on other sites
Tried the include approach... it executed neither of the scripts.

Ammendum: I figure CURL won't work because it operates in the same way 'header' does, it tells the user's browser to execute the request, which I believe won't work with AJAX since it points the user's browser away from the initial page.

I'll have a try though

Share this post


Link to post
Share on other sites
Tell me what result do you expect from calling the script? You want some parameters returned or something?

for curl set curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); --> Then all the result will be return as a string instead of being displayed.

Share this post


Link to post
Share on other sites
Each of the two scripts are simply for testing and read:

[code]<?php

$ajax = "main|";
$ajax = $ajax."Main";
echo($ajax);

?>[/code]

and

[code]<?php

$ajax = "menu|";
$ajax = $ajax."Menu";
echo($ajax);

?>[/code]

What they should do is slot into the original HTML document like so:

[code]<div id="main">Main</div>
<div id="menu">Menu</div>[/code]

This is how the AJAX engine handles any responses from the scripts.

If I make a call to one of them, it works fine but not if I try to call both (using the obviously flawed header method, which I knew would fail but it proves the rest of the code is working since it works in a single instance)

Share this post


Link to post
Share on other sites
Pls read php.net:
[a href=\"http://us2.php.net/manual/en/function.include.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.include.php[/a]

Many good examples listed there. Anyway, Im so sleepy and gotta take a nap now, hope you can find the solution or someone can help.

Cheers.

err, just saw yor reply, try this:
in your included script, echo everything you want to display:
echo " blah blah blah --- This is the main";

PS: If possible post your script here or pm me, at least part of it

Share this post


Link to post
Share on other sites
I can't help but feel that was meant as an insult to my intelligence.

As I've already told you I've tried implementing include, if only just to shut you up after the first time I told you it wouldn't work. You quite clearly don't know how AJAX works, this isn't just slapping a web page on the client, it's about modifying one already on the client machine.

[!--quoteo(post=361346:date=Apr 3 2006, 09:53 PM:name=yellow1912)--][div class=\'quotetop\']QUOTE(yellow1912 @ Apr 3 2006, 09:53 PM) [snapback]361346[/snapback][/div][div class=\'quotemain\'][!--quotec--]err, just saw yor reply, try this:
in your included script, echo everything you want to display:
echo " blah blah blah --- This is the main";

PS: If possible post your script here or pm me, at least part of it
[/quote]

[code]$ajax = "menu|";
$ajax = $ajax."Menu";
echo($ajax);[/code]

That's what it already does...

Share this post


Link to post
Share on other sites
Rushyo, I feel all asleep and I still trying to stay up to help you. And i never in my life insult anyone's intelligence or whatsoever, except mine.

And I for one wouldnt get angry at someone who trying to help me, even if he is of use or not. You will never get any friend this way.

Share this post


Link to post
Share on other sites
"And I for one wouldnt get angry at someone who trying to help me, even if he is of use or not. You will never get any friend this way."

If that person is implying I'm stupid, I wouldn't want to be friends with them.

Forget it, I'll find some way around it myself.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.