Javascript не перенаправляет на новую страницуMySql

Форум по Mysql
Ответить
Anonymous
 Javascript не перенаправляет на новую страницу

Сообщение Anonymous »

У меня небольшая проблема с моим простым чат-ботом, он задает ряд вопросов и ответов с использованием PHP и MySQL, но главным фактором здесь является код Javascript, который показан ниже
// elements used in the chat system //
var sendbutton = document.getElementById('sendbutton');
var userinput = document.getElementById('textbox');
var messagecontainer = document.getElementById('messagescontainer');
var httprequest = new XMLHttpRequest(); // this is for the connection with the php file for responses//
var units;var price;var space; var down;
//---------------------------------//
sendbutton.addEventListener('click',function(e){
//check if the message is empty or not//
if(userinput.value == ""){
alert("Please type in a message");
}else{
window.location = "url.php";
let messagetext = userinput.value; // get the message from the user//
//-- conditions to store user requirements --//
if(messagetext === "Primary" || messagetext === "Resale"){
units = messagetext;
}
if(messagetext == "5" || messagetext == "10" || messagetext == "15"){
down = messagetext;
}
if(messagetext == "5 Million to 10 Million" || messagetext == "10 Million to 30 Million"){
price = messagetext;
}
if(messagetext == "100 - 150" || messagetext == "150 - 250" || messagetext == "250+"){
space = messagetext;
window.open("test2.php?units="+units+"&&price="+price+"&down="+down+"&&space="+space+"");
}
//-------------------------------------------//
SendMessage(messagetext); // send the message to the function//
userinput.value=""; // to remove the text message from the input box after the user presses send//
}
} );
//-------------------------------//

// the action that will happen when the user presses send //
function SendMessage(messagetext){
// create the message response from the user//
var UserMessage = document.createElement('div');
UserMessage.classList.add('w-50');
UserMessage.classList.add('float-end');
UserMessage.classList.add('shadow-sm');
UserMessage.style.margin="10px";
UserMessage.style.padding="5px";
UserMessage.style.backgroundColor="#0dcaf0";
UserMessage.innerHTML="Visitor: "+
""+ messagetext +"";
messagecontainer.appendChild(UserMessage);
//-----------------------------------------//

//---now we send the message of the user to the database using php//
AskDatabase(messagetext);
//scroll to the last message //
messagecontainer.scrollTop = messagecontainer.scrollHeight;
//---------------------------------------------------------------//
}
//-------------------------------------------------//

//--below is the function to ask the database about the user's questions//
function AskDatabase(messagetext){
//ajax used below//
httprequest.open('GET','chatbot.php?message='+messagetext,true);// get the php connection file//
httprequest.send();// send the user message to this php file//
httprequest.onreadystatechange = ChatBotMessage; //send the chat bot response to the user//
}
//----------------------------------------------------------------------//

//the message sent from the chatbot itself//
function ChatBotMessage(){
//check if there is a response from the database//
if(httprequest.readyState == XMLHttpRequest.DONE && httprequest.status == 200){

var BotFeedback = JSON.parse(httprequest.responseText);
// create the message response from the bot//
var BotMessage = document.createElement('div');
BotMessage.classList.add('w-50');
BotMessage.classList.add('float-start');
BotMessage.classList.add('shadow-sm');
BotMessage.style.margin="10px";
BotMessage.style.padding="5px";
BotMessage.style.backgroundColor="#ced4da";
BotMessage.style.height="200px";
BotMessage.innerHTML="Rebot: "+
""+ BotFeedback+"";

messagecontainer.appendChild(BotMessage);
//-----------------------------------------//
//scroll to the last message //
messagecontainer.scrollTop = messagecontainer.scrollHeight;
//---------------------------//

}
//--------------------------------------------//

}
//----------------------------------------//

//-- the below is to automatically select for the user in his input the type of request he wants//
function myFunction(e) {
document.getElementById("textbox").value = e.target.value; // this is the id of the textbox input
}
//-------------------------------------------------------------------------------------------//

Основная проблема в том, что строка:
window.open("test2.php?units="+units+"&&price="+price+"&down="+down+"&&space="+space+"");

не перенаправляется на другую страницу, несмотря на сохранение значений.
Приведенный ниже PHP-код предназначен для справки:


Подробнее здесь: https://stackoverflow.com/questions/793 ... a-new-page
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «MySql»