Jump to content
Sign in to follow this  
misse

How To Include Php Into Javascript Function?

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!! }

Share this post


Link to post
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 ?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...