CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Ajax and Design (http://www.codingforums.com/forumdisplay.php?f=55)
-   -   including php in javascript function (http://www.codingforums.com/showthread.php?t=287790)

purplegraveston 02-17-2013 05:31 PM

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);
}

Old Pedant 02-17-2013 09:40 PM

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.


All times are GMT +1. The time now is 10:27 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.