By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,946 Members | 1,600 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,946 IT Pros & Developers. It's quick & easy.

Execute web page without loading

P: n/a
I'd like to build a function that is executed when someone clicks on an
image. Once clicked, I need some parameters passed to a URL which PHP
will accept and deal with database connections. Sounds simple, and is
simple. The only thing that stumps me is that I do not want that PHP page
loaded anywhere that someone would see it. And preferably no frames if
possible.

Any suggestions?

~ Matthew
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <pa****************************@syr.edu>, Metnetsky
<mi******@syr.edu> writes:
I'd like to build a function that is executed when someone clicks on an
image. Once clicked, I need some parameters passed to a URL which PHP
will accept and deal with database connections. Sounds simple, and is
simple. The only thing that stumps me is that I do not want that PHP page
loaded anywhere that someone would see it. And preferably no frames if
possible.

Any suggestions?

~ Matthew


Set an image tags src attribute to the php page, then hide the image.
--
Randy
Jul 20 '05 #2

P: n/a
I think that you're talking about javascript remoting. I also wish there
was a way to do this. Ideally we could have a php script that reports db
data and have javascript get this data from a url. The only problem is that
if anyone was to send their browser directly to the url that reports the db
data they'd see all the data returned from the db and not the data that we
want them to see on the calling JS page. Let me know if you find any
answers. I've been working on this one for weeks.

Tom

"Metnetsky" <mi******@syr.edu> wrote in message
news:pa****************************@syr.edu...
I'd like to build a function that is executed when someone clicks on an
image. Once clicked, I need some parameters passed to a URL which PHP
will accept and deal with database connections. Sounds simple, and is
simple. The only thing that stumps me is that I do not want that PHP page
loaded anywhere that someone would see it. And preferably no frames if
possible.

Any suggestions?

~ Matthew

Jul 20 '05 #3

P: n/a
Metnetsky <mi******@syr.edu> wrote in message news:<pa****************************@syr.edu>...
I'd like to build a function that is executed when someone clicks on an
image. Once clicked, I need some parameters passed to a URL which PHP
will accept and deal with database connections. Sounds simple, and is
simple. The only thing that stumps me is that I do not want that PHP page
loaded anywhere that someone would see it. And preferably no frames if
possible.

Any suggestions?


Sure. The <script> element allows you to specify a URL in the src
attribute. Most people just put [somefile].js, but it can actually be
something like "getCustomerData.php?nameToFind=met&searchType=lea ding".
The key is that the PHP page (or ASP, JSP, or whatever) must return
JavaScript, not HTML, because it is going to be fed to the JavaScript
interpreter. That solves the first problem, which is how to get
information from the server to the page without causing it to refresh.

The next problem is how to dynamically invoke that method.

var nameSearchElement;
var nameSearchResult;
function doNameSearch ( nameToSearch ) {
if ( nameSearchElement != null ) {
document.body.removeChild ( nameSearchElement );
nameSearchElement = null;
}
nameSearchElement = document.createElement ( "SCRIPT" );
nameSearchElement.src = "getCustomerData.php?nameToFind=" +
encodeURIComponent ( nameToSearch ) + "&searchType=leading";
document.body.appendChild ( nameSearchElement );
}
function doNameSearchComplete ( ) {
// process the nameSearchResult object
}

The doNameSearch function creates the script element, attaches it to
the current document, which in turn causes the browser to ask the
server for the source of the script element. This establishes
communication back to the server and allows you to retrieve the
results.

The server code must return valid JavaScript code. In this example, I
have created a global variable "nameSearchResult" so I know where to
look for the results of the search. It is up to you to define how to
structure that data. This example also defines a callback function,
"doNameSearchComplete", used to signal that the operation is complete.
So, for example, the page could generate the following code:

nameSearchResult = {
numNamesFound: 0,
error: "Database currently unavailable"
};
doNameSearchComplete ( );

The last line invokes the callback function, indicating that the
server roundtrip is complete. Unfortunately, the database was down...

The good thing about this process is that it does not require
plug-ins, ActiveX objects, proprietary calls to internal components,
etc. Just good, old DHTML. The extra sweetener is that you get raw
data as executable code, not HTML or XML that has to be parsed and
then reformatted by other code.

Hope that helps.
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.