javascript和html之间的交互问题,求高手解答

爱奇途 2014-03-18 11:34:30
javascript 怎么通知php处理数据,然后返回结果,javascript继续处理,然后html显示?
...全文
326 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
天狗网络 2014-07-09
  • 打赏
  • 举报
回复
为什么我两个都设置为图片的时候
卧龙派 2014-03-27
  • 打赏
  • 举报
回复
最简单的也就是ajax了,用jquery封装好的 $.ajax 真的很省事 如果你用原生的ajax就代码就要写一堆!
net_php 2014-03-21
  • 打赏
  • 举报
回复
建议LZ看看JQ AJAX方法,应该是你想要的。
爱奇途 2014-03-21
  • 打赏
  • 举报
回复
引用 15 楼 u010541899 的回复:
这个网上很多呀,就是前后台交互问题 ,传输数格式一般用json 比较方面,多百度下吧
一般人都叫多百度下多谷歌下!高手不想帮忙,可以围观,没必要进来说没用的废话!
爱奇途 2014-03-21
  • 打赏
  • 举报
回复
引用 18 楼 net8386308 的回复:
建议LZ看看JQ AJAX方法,应该是你想要的。
jq中得ajax跟js里面的ajax有什么区别?
卧龙派 2014-03-19
  • 打赏
  • 举报
回复
引用 11 楼 wyz365889 的回复:
[quote=引用 8 楼 zfzhuman123 的回复:] 可以不用ajax <script src="url" type="text/javascript"></script>
这个怎么用?就填个url?那参数怎么传回来?[/quote] url里边包含参数咯 不过你php里边要返回 document.write();
再看我一眼 2014-03-19
  • 打赏
  • 举报
回复
引用 10 楼 wyz365889 的回复:
[quote=引用 7 楼 microlab2009 的回复:]
<html>
<head>
<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
function click2()
{
alert("wwww");
$.ajax({
   type: "GET",
   url: "del.php",
   data: "num=3",
   success: function(msg){
     alert( "Data Saved: " + msg );
     //成功html显示结果
   }
});
}
</script>
</head>
<body>
<input type="button" onclick="click2()" value="test">
</body>
</html>
需要加载jquery文件啊 你都没加载怎么能成功呢
哦,折腾下可以了。但是我要传回多个值怎么办?要用拼接,在分割的方法吗?能多个传参回来吗[/quote] 传多个值,也有很多方法 比如拼接字符串等等 然后,我强烈推荐使用json格式 由于ajax返回的都是字符串,所以可以在PHP中把你需要传回的多项数值放进数组, 使用php的json_encode方法将数组转换为json字符串. js接收到以后使用eval方法将字符串解析进数组对象 然后就可以方便的使用了
爱奇途 2014-03-19
  • 打赏
  • 举报
回复
引用 8 楼 zfzhuman123 的回复:
可以不用ajax <script src="url" type="text/javascript"></script>
这个怎么用?就填个url?那参数怎么传回来?
爱奇途 2014-03-19
  • 打赏
  • 举报
回复
引用 7 楼 microlab2009 的回复:
<html>
<head>
<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
function click2()
{
alert("wwww");
$.ajax({
   type: "GET",
   url: "del.php",
   data: "num=3",
   success: function(msg){
     alert( "Data Saved: " + msg );
     //成功html显示结果
   }
});
}
</script>
</head>
<body>
<input type="button" onclick="click2()" value="test">
</body>
</html>
需要加载jquery文件啊 你都没加载怎么能成功呢
哦,折腾下可以了。但是我要传回多个值怎么办?要用拼接,在分割的方法吗?能多个传参回来吗
PhpEr_贵 2014-03-19
  • 打赏
  • 举报
回复
这个网上很多呀,就是前后台交互问题 ,传输数格式一般用json 比较方面,多百度下吧
爱奇途 2014-03-19
  • 打赏
  • 举报
回复
引用 13 楼 zfzhuman123 的回复:
[quote=引用 11 楼 wyz365889 的回复:] [quote=引用 8 楼 zfzhuman123 的回复:] 可以不用ajax <script src="url" type="text/javascript"></script>
这个怎么用?就填个url?那参数怎么传回来?[/quote] url里边包含参数咯 不过你php里边要返回 document.write();[/quote] 没太懂?我要传参数到del.php,del.php处理完数据,传回参数,这个<script src="url" type="text/javascript"></script>东东,怎么拿出参数,接着分析呢?
asasa45645656 2014-03-18
  • 打赏
  • 举报
回复
貌似可以用ajax吧
  • 打赏
  • 举报
回复
我一般用ajax 再联合js 这样做起来很快。
卧龙派 2014-03-18
  • 打赏
  • 举报
回复
可以不用ajax <script src="url" type="text/javascript"></script>
嘻哈大咖秀 2014-03-18
  • 打赏
  • 举报
回复
<html>
<head>
<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
function click2()
{
alert("wwww");
$.ajax({
   type: "GET",
   url: "del.php",
   data: "num=3",
   success: function(msg){
     alert( "Data Saved: " + msg );
     //成功html显示结果
   }
});
}
</script>
</head>
<body>
<input type="button" onclick="click2()" value="test">
</body>
</html>
需要加载jquery文件啊 你都没加载怎么能成功呢
爱奇途 2014-03-18
  • 打赏
  • 举报
回复
引用 5 楼 microlab2009 的回复:
$.ajax({
   type: "GET",
   url: "dealggl.php",
   data: "num="+'<?php echo $iRandNum?>',
   success: function(msg){
     alert( "Data Saved: " + msg );
     //成功html显示结果
   }
});
<html> <head> <title></title> <script type="text/javascript"> function click2() { alert("wwww"); $.ajax({ type: "GET", url: "del.php", data: "num=3", success: function(msg){ alert( "Data Saved: " + msg ); //成功html显示结果 } }); } </script> </head> <body> <input type="button" onclick="click2()"> </body> </html> del.php <?php echo $_GET["num"]; ?> 一直都没成功
嘻哈大咖秀 2014-03-18
  • 打赏
  • 举报
回复
$.ajax({
   type: "GET",
   url: "dealggl.php",
   data: "num="+'<?php echo $iRandNum?>',
   success: function(msg){
     alert( "Data Saved: " + msg );
     //成功html显示结果
   }
});
爱奇途 2014-03-18
  • 打赏
  • 举报
回复
引用 3 楼 microlab2009 的回复:
这种功能只能用ajax 去下个jquery的手册
$.ajax({
   type: "POST",
   url: "some.php",
   data: "name=John&location=Boston",
   success: function(msg){
     alert( "Data Saved: " + msg );
     //成功html显示结果
   }
});
引用 3 楼 microlab2009 的回复:
这种功能只能用ajax 去下个jquery的手册
$.ajax({
   type: "POST",
   url: "some.php",
   data: "name=John&location=Boston",
   success: function(msg){
     alert( "Data Saved: " + msg );
     //成功html显示结果
   }
});
给你个例子 <script type="text/javascript"> var sp = $("#wScratchPad").wScratchPad({ scratchDown: function(e, percent){show(e, percent);}, scratchMove: function(e, percent){show(e, percent);}, scratchUp: function(e, percent){show(e, percent);} }); var myImage='<?php echo $myImage?>'; sp.wScratchPad('width', '115'); sp.wScratchPad('height', '33'); sp.wScratchPad('size', '5'); sp.wScratchPad('image',myImage); //sp.wScratchPad('image2', './images/2.png'); //覆盖在上面的图片 sp.wScratchPad('cursor', './cursors/coin.png'); sp.wScratchPad('reset'); function show(e,percent) { if(percent > 70) { sp.wScratchPad('clear'); window.location.href="dealggl.php?num="+'<?php echo $iRandNum?>'; } } </script> 就是上面判断70的地方,我要给dealggl.php一些数据,写入数据库,然后处理完,回到本页面;用ajax的话要怎么弄
嘻哈大咖秀 2014-03-18
  • 打赏
  • 举报
回复
这种功能只能用ajax 去下个jquery的手册
$.ajax({
   type: "POST",
   url: "some.php",
   data: "name=John&location=Boston",
   success: function(msg){
     alert( "Data Saved: " + msg );
     //成功html显示结果
   }
});
爱奇途 2014-03-18
  • 打赏
  • 举报
回复
引用 1 楼 asasa45645656 的回复:
貌似可以用ajax吧
不用ajax的话,要怎么弄! 还有ajax的要怎么用?

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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