dqeznd1697 2014-05-03 10:13
浏览 44
已采纳

试图通过ajax调用php页面

On submit alert is working but inside ajax code not working. value store in var and go to ajax page where i trying to use mysql insert query but its not working properly. I after ajax success result is not display, For a sec ajax file name shows in NET (error console)

JQuery Code:

$(document).ready(function(){   
$('#submit').click(function(){
var project_ID = $('#project_name').val();
var accommodation=$('#accommodation').val();
var no_of_floors=$('#no_of_floors').val();
var no=$('#no').val();
 if(project_ID==''){
    alert('Select Project Name');
}
if(accommodation==''){
    alert('Select Accomodation Scale');
}
 if($('#typeI').prop('checked')){
    var type1=$('#typeI').val();
    }
if($('#typeII').prop('checked')){
    var type2=$('#typeII').val();
    }
if($('#typeIII').prop('checked')){
    var type3=$('#typeIII').val();
    }
if($('#typeIV').prop('checked')){
    var type4=$('#typeIV').val();
    }
    if(project_ID!="" && accommodation!='') 
   {
    $.ajax({url:"villa_Accomo_type.php?project_ID="+project_ID
   +"&accommodation="+accommodation+"&type1="+type1+"&type2="+type2
   +"&type3="+type3+"&type4="+type4+"&no_of_floors="+no_of_floors+"&no="+no,
      success:function(result){
          res=result;
        alert(res);

     }

}); 
   }
 });
 });

AJAX PAGE

    <?php
$project_ID    = $_GET['project_ID'];
$accommodation = $_GET['accommodation'];
$type1         = $_GET['type1'];
$type2         = $_GET['type2'];
$type3         = $_GET['type3'];
$type4         = $_GET['type4'];
$no_of_floors  = $_GET['no_of_floors'];
$no            = $_GET['no'];

echo $insert = "insert into villas_scale (project_id,scale,type,
  no_of_floors,no)    values('$project_ID',
'$accommodation','$type1','$no_of_floors','$no')";
mysql_query($insert);

echo $insert2 = "insert into villas_scale (project_id,scale,
 type,no_of_floors,no) values('$project_ID',
'$accommodation','$type2','$no_of_floors','$no')";
mysql_query($insert2);

echo $insert3 = "insert into villas_scale (project_id,scale,
  type,no_of_floors,no) values('$project_ID',
'$accommodation','$type3','$no_of_floors','$no')";
mysql_query($insert3);
echo $insert4 = "insert into villas_scale (project_id,scale,
 type,no_of_floors,no) values('$project_ID',
'$accommodation','$type4','$no_of_floors','$no')";
mysql_query($insert4);

?> 
  • 写回答

1条回答 默认 最新

  • dongque4778 2014-05-03 10:19
    关注

    I have to edit so many errors in your code .jsFiddle

    var no = $('#no').val();
    if (project_ID === '') {
        alert('Select Project Name');
    }
    if (accommodation === '') {
        alert('Select Accomodation Scale');
    }
    if ($('#typeI').prop('checked')) {
        var type1 = $('#typeI').val();
    }
    if ($('#typeII').prop('checked')) {
        var type2 = $('#typeII').val();
    }
    if ($('#typeIII').prop('checked')) {
        var type3 = $('#typeIII').val();
    }
    if ($('#typeIV').prop('checked')) {
        var type4 = $('#typeIV').val();
    }
    if (project_ID !== "" && accommodation !== '') {
        $.ajax({
            url: "villa_Accomo_type.php",//This should the url where you send data
            type: 'GET',
            data: project_ID = "project_ID" + project_ID + " & accommodation = " + accommodation + " & type1 = " + type1 + " & type2 = " + type2 + " & type3 = " + type3 + " & type4 = " + type4 + " & no_of_floors = " + no_of_floors + " & no = " + no, // here you need the specify your serialize object 
            success: function (result) {
                alert(result);
    
            }
    
        });
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行