i have a build a javascript which does following: Get content via ajax->php->sql and show it on index.php after clicking the content there will be shown new content.

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

This is my code which shows content:

<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>');

  } 
});

}); } `

有帮助吗?

解决方案

You can send data to the callback script, specified in the URL, by including values in the jQuery.ajax data setting. Depending on what type of request you're making, this data will either be included in the $_GET or $_POST global variables. For example, to POST data to your callback script, you could do:

$.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...
  } 
});

For more information, please read up on the jQuery.ajax function's documentation at https://api.jquery.com/jQuery.ajax/

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top