Send values to $_GET using jQuery

前端 未结 4 668
忘掉有多难
忘掉有多难 2021-01-28 13:30

I\'m using a PHP script that is waiting for two values through $_GET.

I\'m trying to pass those 2 values using jQuery and that\'s where I\'m not too good at.

Her

相关标签:
4条回答
  • function xrate(id,rating){  
    
       $.ajax({
          url: "ajax_xrate.php",
          data: {
              id: id,
              rate:rating
          },
          type: "GET",
          success: function(){
             alert('Bravo!');
          }
       });
    
    }
    
    0 讨论(0)
  • 2021-01-28 14:08
    jquery.ajax work like this
    
    jQuery.ajax({
       url:'you_ur',
       type:'GET'  or 'POST',
       data:{prop1:value1},  // name value pair of props waiting on server
       //etc etc here
    });
    

    http://api.jquery.com/jQuery.ajax/

    0 讨论(0)
  • 2021-01-28 14:15

    you can do:

    function xrate(id,rating){  
    
       $.get("ajax_xrate.php",
          {
              'id': id,
              'rate': rating
          }, 
         function(){
           alert('Bravo!')
         }
      );
    
    }
    
    0 讨论(0)
  • 2021-01-28 14:24
    function xrate(id,rating){  
    
       $.ajax({
              url: "ajax_xrate.php",
              data: "id="+id+"&rate="+rating,
              async:false,
              success: function(){
                 alert('Bravo!');
              }
       });
    
    }
    

    You don't need set parameters like type = 'get' because they are already default. Every parameters shall be inputed in the data: either in string form(like the one above) or object form({id: '45', rate: 'something'}). Async is also true on default in case you didn't know

    0 讨论(0)
提交回复
热议问题