如何通过jPut中的ajax获取JSON数据

时间:2022-10-18 13:56:42

I found a useful jQuery plugin for appending JSON data to HTML contents in an easy way in this link Jput plugin

我找到了一个有用的jQuery插件,用于在这个链接Jput插件中以简单的方式将JSON数据附加到HTML内容

But I would like to know how it is possible to send and get json data thorugh ajax ? Please help me. Thanks in advance.

但我想知道如何通过ajax发送和获取json数据?请帮帮我。提前致谢。

3 个解决方案

#1


5  

//jPut Code
$('#list_div').jPut({
   ajax_url:'data.json', //json url
   ajax_data:data,            //data that you want to send
   name:'list'
});

Please download & go through the docs and samples

请下载并浏览文档和示例

#2


5  

Try this

$.getJSON({
  url: "test.php",
  data:data,

 success:function(response){


        $('#list_div').jPut({
            jsonData:data,  //json
            name:'list'     //jPut name
        },
});

Here test.php should return a json data

这里test.php应该返回一个json数据

#3


2  

For recieving from server

从服务器接收

$.getJSON("sender_url",function(jsond){

  `alert(JSON.stringify(jsond));`

});

OR

$.post("sender_url",{},function(response){

  `var jsond=$.parseJSON(response);`

  `alert(JSON.stringify(jsond));`

});

for sending from client

从客户端发送

var json=[{"id":1,"name":"name1"}{"id":2,"name":"name2"}{"id":3,"name":"name3"}];

$.post("target_url",json,function(reply){

  `alert(reply);

})

Example: target.php

<?php

print_r($_POST);

?>

#1


5  

//jPut Code
$('#list_div').jPut({
   ajax_url:'data.json', //json url
   ajax_data:data,            //data that you want to send
   name:'list'
});

Please download & go through the docs and samples

请下载并浏览文档和示例

#2


5  

Try this

$.getJSON({
  url: "test.php",
  data:data,

 success:function(response){


        $('#list_div').jPut({
            jsonData:data,  //json
            name:'list'     //jPut name
        },
});

Here test.php should return a json data

这里test.php应该返回一个json数据

#3


2  

For recieving from server

从服务器接收

$.getJSON("sender_url",function(jsond){

  `alert(JSON.stringify(jsond));`

});

OR

$.post("sender_url",{},function(response){

  `var jsond=$.parseJSON(response);`

  `alert(JSON.stringify(jsond));`

});

for sending from client

从客户端发送

var json=[{"id":1,"name":"name1"}{"id":2,"name":"name2"}{"id":3,"name":"name3"}];

$.post("target_url",json,function(reply){

  `alert(reply);

})

Example: target.php

<?php

print_r($_POST);

?>