download jsp project - javascript

I have jsp from server-side. When i make ajax call with jquery from client-side there is response with empty spaces which is generated by scriptlet from JSP.
JSP in its turn connects to database and retrieves login if exists and sends response - a single word.
If there is no such row it does not do anything, so the response is almost empty (when I say empty I mean there are empty spaces, tabs and line drops).
So how to remove those absolutely empty spaces in response.
The code is
<!DOCTYPE html>
<html>
<head>
<script src="js/jquery.min.js"></script>
<script>
i = 0;
$(document).ready(function(){
$("input").keyup(function(){
$.post("checkLogin.jsp",
{
login: $('input').val(),
},
function(data,status){
$('#error').html(data.length);
});
});
});
</script>
</head>
<body>
Enter your name: <input id='input' type="text">
<p style="background-color: red;" id="error"></p>
</body>
</html>`

Try to use Maven, once run it will install all the required dependencies in your .m2(C:\Users\username) folder.
You can use the following for your reference.
http://www.mkyong.com/maven/how-to-install-maven-in-windows/
http://www.mkyong.com/maven/where-is-maven-local-repository/

Related

The action tag is not working in live server vs code

I am trying to run html file using the form in the vs code. But the live server is not allowing it to run. I tried it with normal chrome to run the file both files are running in normal chrome but not on the live server also it is navigation to welcome file when submit is clicked. Don't know what's wrong with the vs code.
Code below:
welcome.html
<head>
</head>
<body>
<h1>Welcome To The Prajakta's LOGIN</h1>
</body>
</html>
Validateform
<html>
<head>
<script>
function val()
{
var name=document.getElementById("txtname").value;
var pass=document.getElementById("txtpass").value;
/* if(name==null||name=="")
{
alert("Name cannot be blank")
return false;
}
else if(pass.length<6)
{
alert("Minimum length of password should be more than 6");
return false;
}*/
}
</script>
</head>
<body>
<form method="POST" action="welcome.html" onsubmit="val()">
Name : <input type="text" id="txtname" name="txtname"><br>
Password : <input type="password" id="txtpass" name="txtpass"><br>
<input type="submit" value="Click here">
</form>
</body>
</html>
I tried it with normal chrome to run file both files are running in normal chrome but not in live server.
When you are running on the live server, your form is sending a POST request to the /welcome.html file which is no handing that request that is why you are receiving 405 Method Not Allowed
There should be something at the back that handles the POST method, called as server-side or back-end technologies. Each server-side language (PHP, Python, Ruby, Java, C#, etc.) has its own mechanism of handling form data.
Example welcome.php
<html>
<body>
<h1>Welcome To The Prajakta's LOGIN</h1>
Hi <?php echo $_POST["txtname"]; ?>
</body>
</html>

why script doesnt run?

Well i am working on a website wordpress and i want to add javascript code to the article but it doesnt run !!
<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script type="text/javascript">
document.write(5 + 6);
</script>
</body>
</html>
here the code , i tried custom field but it doesnt work also .
enter image description here
where i add the code exactly
If you're using gutenberg editor then you need to add custom html block to print out your script.
Check my backend screenshot: https://prnt.sc/rjqti4
Check my frontend screenshot: https://prnt.sc/rjqu3y
And if you're trying to do it on custom code then you should go for create a custom template or on single.php or on page.php file you simply use this code to load the desired items. Basically this is not the proper way to add script in WordPress though if you're using this script only on certain pages.
I would assume wordpress is stripping it out, you may need a plugin such as https://wordpress.org/plugins/simple-embed-code/#description to use script tags inside a post
You can add javascript code inside WordPress post > "Text" tab like:
<script type="text/javascript">// <![CDATA[
document.write(5 + 6);
console.log("Please check console: ", (5+6));
// ]]></script>
After adding this, save the WP post and then view the page in the browser.
<!doctype html>
<html lang="en">
<head>
<title>Greetings Page</title>
<link rel="stylesheet" href="./first.css" />
</head>
<body>
<h1>Greetings</h1>
<p id="greeting">Hello, World</p>
<script type="text/javascript">
setTimeout(function() {
document.getElementById('greeting').innerHTML = 'Hello JavaScript!';
}, 3000);
</script>
</body>
</html>

Selecting an element from the jquery POST data

I have been trying to fetch the result of a php page after sending a post request to the page itself. I want to fetch the data after the post request succeeded and get the content of the div element with id result. Here is the code:
<!DOCTYPE html>
<html>
<head>
<title>My Form</title>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#myForm").submit(function() {
$.post("test.php",
{
name: "valid"
},
function(data, status) {
});
return false;
});
});
</script>
</head>
<body>
<form method="POST" id="myForm">
<input type="text" name="name" />
<input type="submit" name="submit" value="Submit" />
</form>
<div id="result">
<?php
if(isset($_POST['name'])) {
if($_POST['name'] == 'valid') {
echo 'You are a valid user!';
}
}
?>
</div>
</body>
</html>
When I submit the button regardless of what is written in the textbox I should get the Your a valid user message from the test.php I want to get this message in the result page and display it in the current page without reloading the page. Since the result page content is saved in data variable I don't know how to select an element which is contained in a variable instead of the current page itself. We can do $("div#result").text() for the current page. But how should I do it for the html content stored in a variable?
Just give your data variable as second parameter to jQuery like this:
$('#result', data).text()
Not tested but should work.
Update:
I don't know why but this will only work when your element you want to find is wrapped with another element within your body tag. See this fiddle: http://jsfiddle.net/xf32L5uj/

JQuery & advanced javascript

i am trying to get a value in input box automatically by clicking button "get name", from database. how can i implement it...?
my so far work is below...
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
var n = $("#div2").load("getTotal.html #p1").val();
$("#div2").val(n);
});
});
</script>
</head>
<body>
<input type="text" id="div2" value=""/>
<button>Get Name</button>
</body>
</html>
and getTotal.html page contents...
<h2>jQuery and AJAX is FUN!!!</h2>
<p id="p1">John D. Feller</p>
in doing so.... i am getting an error "[object, Object]".
Help me out....with this error and advice me how can i take values from database.
Issues in the code:
1) $("#div2").load(...) doesn't make much sense because it's telling jQuery to pull the content of the URL as HTML content of #div2. Here #div2 is an input which is not supposed to have HTML content. http://api.jquery.com/load/
2) You may want to load only the content of #p1 by using getTotal.html #p1, but this syntax won't work as you expected. jQuery can only pull the full content of getTotal.html, then you need to extract content of #p1 from it.
Assuming getTotal.html page is in same directory as your main page, the JS code can be modified to:
$(document).ready(function(){
$("button").click(function(){
$.get("getTotal.html", null, function(text) {
$("#div2").val($(text).filter("#p1").html());
});
});
});

using xampp, open a .php file FROM a .php file

I'm trying to write a Roman Numeral Converter for php practice that has an input page where the user specifies whether their input is Roman or Numeric, writes the input, and hits submit. This info will then be passed via URL to an output page where the actual conversion happens. Everything for the output is done, but I can't test it because I can't figure out how to open the output php file when the user hits submit. When I change the URL to be opened to a site on the web, it works fine, but even without including the parameters to pass through the URL I just can't get it to open another php file via localhost.
The javascript to go to the output is as follows:
<script type="text/javascript">
function goToOutput(){
var newURL = "http://localhost/Code/RomanNumeral/RNEnd.php";
window.open(newURL);
return false;
}
</script>
I'll obviously have to later add the variables to the URL in order to execute the conversion, but I'm currently using RNEnd.php (which just writes "success") instead of the actual file just to test the javascript, and its not working. If I just type that newURL into my browser, it opens fine.
Any suggestions? I'd be happy to answer any clarification questions if I wasn't clear.
Thanks
whole code as requested for this specific file is here:
<html>
<head>
<link rel="stylesheet" href="RNStyle.css" type="text/css" media="screen"/>
<title>ROMAN NUMERAL CONVERTER - INPUT</title>
<script type="text/javascript">
function goToOutput(){
var newURL = "http://localhost/Code/RomanNumeral/RNEnd.php";
window.open(newURL);
return false;
}
</script>
</head>
<body background="http://upload.wikimedia.org/wikipedia/commons/5/53/Colosseum_in_Rome,_Italy_-_April_2007.jpg">
<div id="RomanNumeralInput">
<h1>ROMAN NUMERAL CONVERTER</h1>
<P>Select your input type and then enter the number.</P>
<form name="convertform" onSubmit="return goToOutput();">
<select name="valuetypes">
<option value="R">ROMAN</option>
<option value="N">NUMERIC</option>
</select>
CONVERT:
<input type="text" name="numcon">
<input type="submit" name="convertSubmit" value="CONVERT">
</form>
</div>
</body>
</html>
If you are using HTML form for SUBMIT, then you should specify the output page url in the onSubmit action.
Else if you are trying to do it through Javascript, I would suggest you use AJAX call to pass the parameters along with URL and get the output of the page and display.

Categories

Resources