html中ajax的url路径问题

WZYZL 2016-07-27 03:18:46
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>测试页面</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<script type="text/javascript" src="${root!}/assets/js/libs/jquery-3.1.0.min.js"></script>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">

function ok(){
var date=$("#ff").serialize();
alert("123");
$.ajax({
type:"post",
url:"/message",
data:date,
success:function(obj){
alert(obj);
}
});

}

</script>
</head>

<body>

<form id="ff" action= "/message" method="post">
短信内容:<input type="text" name="name"/><br/>
手机号码:<input type="text" name="password"/><br/>
模板ID:<input type="text" name="id" value="40285284557358c101557b01f4550050">
<input type="button" value="提交" onclick="ok();"/>
</form>
</body>
</html>



想要把这几个参数传到后台的一个方法上,求各位大神url跟表单中的action怎么写,怎么写都不对,能够弹出窗口123
...全文
1184 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
RockeyCui 2016-08-03
  • 打赏
  • 举报
回复
testServlet在web.xml里配置了么?
Bug开发攻城狮 2016-08-03
  • 打赏
  • 举报
回复
如果不知道这么写url路径,那你就直接写绝对路径啊
WZYZL 2016-07-28
  • 打赏
  • 举报
回复
/shengwang/message/com/sw/test/testServlet.java 我想要进入这个类里面,url应该怎么写啊
WZYZL 2016-07-28
  • 打赏
  • 举报
回复
有报错吗?,ajax请求加个error 看看。 没有报错,就是不知道url路径怎么写,怎么写都不对
xw4501339 2016-07-28
  • 打赏
  • 举报
回复
引用 4 楼 WZYZL 的回复:
/shengwang/message/com/sw/test/testServlet.java 我想要进入这个类里面,url应该怎么写啊
要加上你们框架后台配置的URL参数 5L说的不错,直接问你们后端,URL怎么写
qq20004604 2016-07-28
  • 打赏
  • 举报
回复
问你们后端。。。。。。
xw4501339 2016-07-27
  • 打赏
  • 举报
回复

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
  <head>
    <title>测试页面</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">       
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
 <script type="text/javascript" src="./jquery-1.8.2.js"></script>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">

function ok(){
	var date=$("#ff").serialize(); 
	$.ajax({
		type:"post",
		url:"./message.php",      //这里指向你要操作路径
		data:date,
		success:function(msg){
			console.log(msg);
		}
	});
}

</script>
  </head>
  
  <body>
  
    <form id="ff">
     短信内容:<input type="text" name="name"/><br/>
     手机号码:<input type="text" name="password"/><br/>
     模板ID:<input type="text" name="id" value="40285284557358c101557b01f4550050">
     <input type="button" value="提交" onclick="ok();"/>
    </form>
  </body>
</html>
/*************************************/

<?php
$name = $_POST['name'];
$password = $_POST['password'];
$id = $_POST['id'];

/******这里处理你要的逻辑************/

$content = array('1'=>1,'2'=>2);   //这个数据是死的,改成获取你想要的
 echo json_encode($content);
Null_Reference 2016-07-27
  • 打赏
  • 举报
回复
有报错吗?,ajax请求加个error 看看。

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧