Php 使用javascript更改包含方向
我正在尝试用JavaScript更改包含路径。必须从这开始Php 使用javascript更改包含方向,php,javascript,html,Php,Javascript,Html,我正在尝试用JavaScript更改包含路径。必须从这开始 <?php include 'sections/welcome.php'; ?> 对此 <?php include 'sections/new_visitor.php'; ?> 对此 <?php include 'sections/nda.php'; ?> 等等。。。有人知道如何用JavaScript编码吗?你不能通过JavaScript改变PHP的编码方式。您可以通过javascr
<?php include 'sections/welcome.php'; ?>
对此
<?php include 'sections/new_visitor.php'; ?>
对此
<?php include 'sections/nda.php'; ?>
等等。。。有人知道如何用JavaScript编码吗?你不能通过JavaScript改变PHP的编码方式。您可以通过javascript将变量发送到php,然后php响应这些变量。。。看起来你有各种各样的注册。如果您使用的是标准HTTP请求,那么可以使用javascript将$\u GET变量附加到操作链接。例如:
$('#form').attr('action', $('#form').attr('action') + '?page=welcome');
然后,单击链接,PHP将访问$_GET['page'],因此在PHP中您可以:
switch($_GET['page'])) {
case 'welcome':
include 'section/welcome.html';
break;
case 'nda':
include 'section/nda.html';
break;
}
请看下面的if(message==1)语句:)对不起,我是这样一个noob:p
var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject(){
var xmlHttp;
if(window.ActiveXObject){
try{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
xmlHttp = false;
}
}else{
try{
xmlHttp = new XMLHttpRequest();
}catch(e){
xmlHttp = false;
}
}
if(!xmlHttp){
alert("cat create that object hos");
}
function newuser(){
if(xmlHttp.readyState ===0 || xmlHttp.readyState ===4){
name = encodeURIComponent(document.getElementById('name').value);
company = encodeURIComponent(document.getElementById('company').value);
nationalities = encodeURIComponent(document.getElementById('nationality').value);
phonenumber = encodeURIComponent(document.getElementById('phonenumber').value);
queryString = "?name=" + name + "&?company=" + company + "&?nationalities=" + nationalities + "&?phonenumber=" + phonenumber + "&?URL= newuser";
xmlHttp.open("GET", "/php/database.php?" + queryString, true);
xmlHttp.onreadystatechange = handleServerResponse;
xmlHttp.send(null);
}else{
setTimeout('newuser()', 1000);
}
}
function handleServwerResponse(){
if(xmlHttp.readyState ===4){
if(xmlHttp.status === 200){
xmlResponse = xmlHttp.responseXML;
xmlDocumentElement = xmlResponse.documentElement;
message = xmlDocumentElement.firstChild.data;
if(message === 1){
//我想在这里调用一个函数,这样就可以更改include路径
}else{
document.getElementBy("underInput").innerHTML = 'User already exist klick to sign in here <p style="color:blue" onclick=""></p>';
}
}
}
}
}
}其他{
document.getElementBy(“underInput”).innerHTML='用户已存在请单击此处登录”;
}
}
}
}
}
我们的CRM系统就是这样做的,所以我支持这种方法OK!谢谢:D但是我怎么把它和feks联系起来呢。提交按钮?哦,等等,我想我明白你的要求了。。。您需要将$\u GET变量添加到表单操作中。。。请看我的最新答案。请看我下面的答案/问题:)很高兴听到。请发布您的解决方案,以便其他人受益,如果我的回答有帮助,请接受!我不确定你到底想做什么。如果您只是试图更改服务器返回的数据,那么您应该让服务器从最初的ajax调用返回适当的数据。编写服务器返回以返回javascript所需的数据,而不是返回状态,并让javascript尝试更改所包含的内容。在您的示例中,message===1,您是否可以改为编写message===“javascript需要的任何内容”?