Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-17-2013, 05:31 PM   PM User | #1
purplegraveston
New to the CF scene

 
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
purplegraveston is an unknown quantity at this point
including php in javascript function

hi all, thanks in advance for looking...

im trying to run a javascript function that does one thing in a div called "idGenre" when the function is called and it works okay no probs, but i all, but now i also want it to somthing else when that function is called as well. I want it to call or include a php script in another <div> called "idMain" to run the script in that div too, i did it a long time ago but have forgotton how i did it, could you please help?

function fnGenre(genre){
var xmlhttp; if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
var params = "genre="+genre;
xmlhttp.open("POST", "genre.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("idGenre").innerHTML=xmlhttp.responseText;


in here i want it to say somthing like ...
document.getElementById("idMain").include "show.php";

} }
xmlhttp.send(params);
}
purplegraveston is offline   Reply With Quote
Old 02-17-2013, 09:40 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,198
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
You can't do it.

At least nothing like that.

You must either put the PHP output into the <div> *AS THE PAGE IS CREATED* by your PHP page code *OR* you must use AJAX to go grab the content and use innerHTML to put it in place.

In either case, you can't "run" the PHP script in the browser. PHP must be run on the server and must send back *ONLY* HTTP responses (usually HTML, but could be binary response) to the browser.

I think you are badly confused.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Reply

Bookmarks

Tags
javascript

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:24 AM.


Advertisement
Log in to turn off these ads.