简体   繁体   English

在jquery,Ajax中导航页面

[英]Navigating pages in jquery,Ajax

I'm new in jquery and ajax, i just want to open all my navigation links in one page. 我是jquery和ajax的新手,我只想在一页中打开所有导航链接。 I also divided my page in three division. 我也将页面分为三个部分。 1st page is in html ie welcome.html and rest all are in jsp. 第一页是html,即welcome.html ,其余所有都是jsp。 simply program takes two numbers, performs arithmetic operations on server (i wrote the servlet for each operation) side and send result back to jsp. 简单的程序接受两个数字,在服务器端执行算术运算(我为每个运算编写了servlet),然后将结果发送回jsp。 At first it opens on same page but when i click on calculate button it goes on next page. 首先,它在同一页上打开,但是当我单击“计算”按钮时,它在下一页上显示。 if anybody have this solution using ajax or jquery plz let me know . 如果有人使用ajax或jquery plz有此解决方案,请告诉我。

在此处输入图片说明 在此处输入图片说明 在此处输入图片说明 在此处输入图片说明

It's probably because the calculate button submits the form. 可能是因为“计算”按钮提交了表单。 Try calculating the value with JQuery/AJAX. 尝试使用JQuery / AJAX计算值。

Keep it like this(Using javascript, though you can use jquery also): 保持这样(使用javascript,尽管您也可以使用jquery):

Say the id of first number relaed input field is val1 and that of second value is val2, Keep this javascript function code in your jsp at bottom: 假设第一个数字涉及的输入字段的ID是val1,第二个值的ID是val2,请将此javascript函数代码保留在jsp中的底部:

<script>
function calculate(operation){
var value1, value2, result;
value1=document.getElementById("val1").value;
value2=document.getElementById("val2").value;
if(operation=='add')
result=value1+value2;
else if(operation=='subtract')
result=value1-value2;
else if(operation=='multiply')
result=value1*value2;
else if(operation=='divide')
result=value1/value2;
else
result="invalid choice!";
return result;
}
</script>

Each time on calculate button(like add, subtract, multiply, divide) keep:
for add button-> onclick=calculate('add')
for subtract button-> onclick=calculate('subtract')
for multiply button-> onclick=calculate('multiply')
for divide button-> onclick=calculate('divide')

inside calculate button onclick event. 内部计算按钮的onclick事件。

Note: If you really want to use servlets, use ajax call for that with your existing code, you can see an example here and here 注意:如果您确实要使用servlet,请对现有代码使用ajax调用,您可以在此处此处查看示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM