通过AJAX发送数据 [英] Sending data via AJAX

查看:57
本文介绍了通过AJAX发送数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个内置的javascript,它可以执行以下操作: 通过ajax-> php-> sql获取内容,并将其显示在index.php上 单击内容后,将显示新内容.

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.

现在,我想拥有一个功能,可以在将内容单击到php之后发送数据,该功能将在db中执行某些操作.如何创建将发送数据的功能?谢谢!

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

  } 
});

}); } `

}); } `

推荐答案

您可以通过在jQuery.ajax data设置中包含值来将数据发送到URL中指定的回调脚本.根据您发出的请求类型,此数据将包含在$_GET$_POST全局变量中.例如,要将数据发布到回调脚本中,您可以执行以下操作:

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

有关更多信息,请在 https://api上阅读jQuery.ajax函数的文档. jquery.com/jQuery.ajax/

这篇关于通过AJAX发送数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆