dongpi2503
2018-06-22 00:59 阅读 36

JQUERY Ajax多帖[关闭]

var name = "gökhan";
var surname = "sahiner";
var id = 12;

$.ajax({
    type: "POST",
    url: "newlevels.php",
    data: name,
    success: success,
    dataType: dataType
});

Hi i want multi post but I've been searching everywhere and I did not understand only i have been found this. how can i post. 3 type

</div>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

3条回答 默认 最新

  • 已采纳
    dongqi6964 dongqi6964 2018-06-22 01:06

    There are a few ways you can do this. You can create an object and POST the object, you can serialize the form (also an object), or you could simply seperate it with a comma.

    var name = "gökhan";
    var surname = "sahiner";
    var id = 12;
    $.ajax({
        type: 'POST',
        url: 'newlevels.php',
        data: { nameI: name, 
                surnameI: surname,
                idI: id
        },
        success: function(rsp){
          //
        },
        fail: function(rsp) {
            // Nothing
        }
    });
    

    newlevels.php

    $Name = $_POST["nameI"];
    $Surname = $_POST["surnameI"];
    $ID = $_POST["idI"];
    
    点赞 评论 复制链接分享
  • dqc19941228 dqc19941228 2018-06-22 01:27

    I fully agree with @Timothy , this will work . Also you can have a look below :-

    var name = "gökhan";
    var surname = "sahiner";
    var id = 12;
    var array = name+'|'+surname+'|'+id ; // Create an array with the variables and pass this array and on the other page just explode it to get the separate values
    
    $.ajax({
      type: "POST",
      url: "newlevels.php",
      data: array,
      dataType: dataType,
      success: function(){//Your function goes here}
    });
    
    点赞 评论 复制链接分享
  • dozug64282 dozug64282 2018-06-22 02:19

    Have a look at this one:-

    $(document).ready(function(){
        $("#button").click(function(){ //Expecting the event on a button click  
            var name = "gökhan";
            var surname = "sahiner";
            var id = 12;
            var array = name+'|'+surname+'|'+id ;
    
            var xmlhttp ;           
            if (window.XMLHttpRequest){             
                xmlhttp = new XMLHttpRequest();             
            }           
            else{               
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");               
            }           
            xmlhttp.open("GET","newlevels.php?array="+array,true);          
            xmlhttp.send();         
            xmlhttp.onreadystatechange=function(){              
                if (xmlhttp.readyState==4 && xmlhttp.status==200){                  
                    var result = xmlhttp.responseText ;                 
                    if (result == 1){                       
                        //Your code for success return                  
                    }                   
                    else{
                        //Your code if return is not a success
                    }                   
                }               
            }           
        });
    });
    

    Hope this will work, let me know if any error comes.

    点赞 评论 复制链接分享

相关推荐