Sending data via AJAX

I have a javascript assembly that does the following: Get the content via ajax-> php-> sql and show it on index.php after clicking on the content, new content will appear.

Now I want to have a function that sends data after the content is clicked on php, which will do something in db. How can I create a function that will send data? Thanks!

This is my code that shows the contents:

<script id="source" language="javascript" type="text/javascript">
function laden(){
$(function() 
{

$.ajax({                  
`usr_id`                    
  url: 'content/get.php',              


  dataType: 'json',                   
  success: function(data)         
  {
    var id = data[0];             
    var name = data[1];

    var count = data[3];


    $('#output').html('<div onclick="laden('+id+')" id="content"></div>');

  } 
});

}); } `

+1
source share
1 answer

script, URL, jQuery.ajax data. , , $_GET, $_POST. , POST script :

$.ajax({                    
  url: 'content/get.php',     
  type: 'post', // performing a POST request
  data : {
    data1 : 'value' // will be accessible in $_POST['data1']
  },
  dataType: 'json',                   
  success: function(data)         
  {
    // etc...
  } 
});

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

+8

Source: https://habr.com/ru/post/1623284/


All Articles