jquery ajax PHP 取得选中多选项值并传递到PHP进行删除

244 篇文章 3 订阅
128 篇文章 1 订阅

jquery 取得选中多选项值并传递到PHP网页

PHP网页收到数据,根据所操作的结果返回参数或者值。

比如,删除成功返回什么,删除失败返回什么

弹出窗口引用 :http://layer.layui.com/


index.html代码


<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layer-更懂你的web弹窗解决方案</title>
<link rel="stylesheet" href="css/style.css" type="text/css"/>
<link rel="stylesheet" href="layui/css/layui_up.css" type="text/css"/>
<script type="text/javascript" src="http://libs.baidu.com/jquery/1.8.3/jquery.min.js"></script>
  <script src="layer/layer.js"></script>
  <script src="layui/layui.js"></script>
</head>
<body>
    <input type="checkbox" name="checkbox" value="1"/>1  
    <input type="checkbox" name="checkbox" value="2"/>2
    <input type="checkbox" name="checkbox" value="3"/>3 
    <input type="checkbox" name="checkbox" value="4"/>5  
    <input type="checkbox" name="checkbox" value="5"/>6 
        <div id="myDiv"><h2>通过 AJAX 改变文本</h2></div>
        <button id="testAjax" type="button">Ajax改变内容</button>
<script type="text/javascript">
$(function(){
        //按钮单击时执行
      $("#testAjax").click(function(){
            //取得选中的多项值
            var str="";
            $("input[name='checkbox']:checkbox").each(function(){ 
                if($(this).attr("checked")){
                    str += $(this).val()+","
                }
            })
			  
              //Ajax调用处理
            var html = $.ajax({
               type: "POST",
               url: "index4.php",
               data: "all_id="+str,//在php中data: "name=$tt&id=$id&content="+text,
               async: false


            }).responseText;
			   //成功后返回来的参数 弹出窗口
                    $("#myDiv").html('<h2>'+html+'</h2>');
						  layer.ready(function(){ 
								  layer.open({
									type: 1,
									title: '欢迎页',
									area: ['420px', '240px'], //宽高
									content: html,//返回的参数代码
										btn: ['立即投资', '取消'],  
										shadeClose: true,  
										//回调函数  
										yes: function(index, layero){  
										   self.location='http://www.baidu.com';//立即投资按钮  
										},  
										btn2: function(index, layero){  
										   self.location='http://www.163.com';//取消按钮  
										},  
										cancel: function(index,layero){ //按右上角“X”按钮  
										   self.location='http://www.qq.com';  
										},  
							  });
                              setTimeout(function(){//两秒后跳转   
                                 location.href = "type.php";//PC网页式跳转    
                              },2000); 
		  });
      });
 });
</script> 
</body>
</html>


index4.php代码

<?php
$msg1='所有ID'.$_POST['all_id'].'!';
//数据过程不列出

if(删除成功){
	$msg="成功".$msg1;
	echo $msg;	
}else{//删除失败
	$msg="失败".$msg1;
	echo $msg;		
}

?>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值