Jump to content

How To Include Php Into Javascript Function?


misse

Recommended Posts

i have a java script code contains a function that should include php code(contains mySQL queries and html tags included in echo'') into it, my question is how to write these stuuf into the javascript function:***HTML CODE:<scritpt type="text/javascript" scr="../../load.js"></script>***JS DOCUMENT:function load(){// here is where i want to include my php code!! }

Link to comment
Share on other sites

come oooooon guyz! can`t somebody help me ??!? i`ll describe my idea to make it clear: i have a forum, on its home page, and while it is loading, i want to fetch sections`names from database and write them into a specific DIV in home page, i think it is possible by using javascript and PHP. if not, how can i employ AJAX to do so ?

Link to comment
Share on other sites

First, "calm down"... or so to speak. This is a forum, not a chat. You can't expect an instant answer, and besides, it's sunday.I think you're having a classical case of "language mixup" on your hands. You need to step back, and realize what's really going on, and in what order. Only then will you be able to push up each language to its full potential.Think of it as a Zen excersize (meditation of a sort).Now, let me explain to you how it works... make sure it sinks in before you ask your question again...1. The client makes an HTTP request.2. Your file gets processed by the web server. If it's PHP (or another file which is configured to run as PHP), PHP starts executing, and eventually delivers a response. If not, it's just passed along.3. The browser processes the response.4. The (X)HTML is parsed, i.e. translated into a structure that the browser's inner code can use.5. The (X)HTML starts being evaluated while being parsed, or in other words, the browser starts to perform your instructions.6. Upon evaluating your script element, the browser stops parsing and evaluating the (X)HTML, and if you don't have a "src" attribute, continue to 7. If you have a "src" attribute, repeat 1 to 3, and skip to 7.7. The JavaScript is parsed.8. The JavaScript syncronious codes are then evaluated. Almost all codes in JavaScript are syncronious.9. The (X)HTML resumes to get parsed and evaluated until the next script element or closing html tag.10. If there are asyncronious codes (setTimeout(), setInterval(), XMLHttpRequest()), they get executed as specified or as soon as possible, which may mean during the continuing HTML parsing and evaluation (9). All syncronious code inside is executed as guided by the asyncronious function.What XMLHttpRequest() (a.k.a. AJAX) does is to perform 1 to 3. If the response is X(HT)ML, as per the name, it can also do 4, and allows you to access the mentioned "inner code" with the "responseXML" property. The "innerHTML" property of many objects does 4. If you set an existing element's "innerHTML", 5 and 6 are also performed. The famous eval() function does 7, 8 and 10. Read the JavaScript and AJAX tutorial if you don't understand what I just said with this last paragraph.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...