NYCPHP Meetup

NYPHP.org

[nycphp-talk] Can Javascript call a PHP program and read the results?

tedd tedd.sperling at gmail.com
Wed Jun 1 17:10:46 EDT 2011


At 4:05 PM -0400 5/31/11, David Roth wrote:
>Hi Tedd.
>
>Thanks for your e-mail.
>
>That's returning a graphic and I was looking to get a return of text 
>so the Javascript could make use of it. Unless I overlooked 
>something in your example?
>
>Best regards,
>
>David


David:

No problem returning text either.

http://webbytedd.com/a/ajax-site/

You just need to figure out how to use AJAX (actually AHAH) to send 
commands from the client-side browser to the server-side php script 
to do something. After which, the php script then returns the 
required text (HTML) that a client-side Javascript routine via DOM 
scripting uses to alter the current page DOM presenting a different 
layout to the browser/user.

The HTML is there and so is the Javascript. The only thing you need 
is the slave.php script that receives the commands via a GET (see the 
Javascript routines).

The slave.php script simply takes the command and then sends back the 
HTML needed to create the next page.

It's very simple. You should be able to do this  (I figured it out) 
-- if you can't, then I am available for hire.  Please contact me 
off-list.

Cheers,

tedd


----


>
>On May 31, 2011, at 10:41 AM, tedd wrote:
>
>>At 2:42 AM -0400 5/30/11, David Roth wrote:
>>>I'm using Tumblr.com for a blog platform for a new website. It has 
>>>a lot of benefits as a blog, but it also has the restriction of 
>>>not being able to embed PHP code in the HTML theme template. (Yes, 
>>>I know, my feelings exactly! :-) )
>>>
>>>But Tumblr does support Javascript. What I'm trying to do is get 
>>>the county code of the user so that different links can be 
>>>presented to them that matches their country. Serving up different 
>>>links based on the country code would be handled by Javascript.
>>>
>>>There is a Javascript Google library jsapi, but it doesn't work 
>>>properly for county code. For example,  I'm in the New York City 
>>>metro area and it says I'm in Canada, not the US. I don't 
>>>recalling having this kind of problem with PHP scripts, so I'd 
>>>like to use a PHP script. But I don't know of a way in JavaScript 
>>>to be able to call a PHP script and make the result accessible 
>>>with the Javascript so it can serve up the correct country links.
>>>
>>>I admit I've not done much Javascript programming compared to PHP, 
>>>so I'm not sure if I'm overlooking something. Maybe this is a AJAX 
>>>and jQuery task? I'd appreciate it if someone could offer a 
>>>workable solution.
>>>
>>>Thanks in advance!
>>>
>>>David Roth
>>
>>David:
>>
>>Certainly a Javascript program can call a php script -- here's a demo:
>>
>>http://webbytedd.com/b/timed-php/
>>
>>There's a description at the site.
>>
>>Cheers,
>>
>>tedd
>>
>>--
>>-------
>>http://sperling.com/


-- 
-------
http://sperling.com/



More information about the talk mailing list