jquery$.post函数';s结果数据

jquery$.post函数';s结果数据,jquery,ajax,json,post,Jquery,Ajax,Json,Post,当我调用ajax时(参见下面的代码),什么是“数据”。如何设置和获取数据 // $.post() $("#post").click(function(){ $("#result").html(ajax_load); $.post( loadUrl, {language: "php", version: 5}, function(data){ $("#result")

当我调用ajax时(参见下面的代码),什么是“数据”。如何设置和获取数据

//  $.post()  
 $("#post").click(function(){  
     $("#result").html(ajax_load);  
     $.post(  
         loadUrl,  
         {language: "php", version: 5},  
         function(data){  
             $("#result").html(data);  
         },  
         "json"  
     );  
 });
报告说,数据“可以是xmlDoc、jsonObj、html、文本等”。它是服务器为您使用给定参数指定的loadUrl返回的内容(在您的示例中,是语言:“php”,版本:5),因此您需要检查服务器返回的内容

只需在回调中发出警报(数据),您就会看到返回的内容

更新:将“responseText”重命名为“data”,因为OP将问题改为“data”。

表示数据“可以是xmlDoc、jsonObj、html、文本等”。它是服务器为您使用给定参数指定的loadUrl返回的内容(在您的示例中,是语言:“php”,版本:5),因此您需要检查服务器返回的内容

只需在回调中发出警报(数据),您就会看到返回的内容

更新:将“responseText”重命名为“data”,因为OP将问题更改为“data”。

例如,我使用:

$(document).ready(function(){
$("#btSend").click(function() {
    $.post("/Ajax/script.php", {nome: $("#nome").val(), email: $("#email").val()}, function(data) {
        alert(data);
    });
    return false;
});
}))

script.php返回我想要显示的内容,但是您可以更改为使用“data”进行另一个操作。“btSend”是一个图像,“nome”和“email”是html文本框

这是有效的:)

例如,我使用:

$(document).ready(function(){
$("#btSend").click(function() {
    $.post("/Ajax/script.php", {nome: $("#nome").val(), email: $("#email").val()}, function(data) {
        alert(data);
    });
    return false;
});
}))

script.php返回我想要显示的内容,但是您可以更改为使用“data”进行另一个操作。“btSend”是一个图像,“nome”和“email”是html文本框


这是有效的:)

数据是输入的序列化值。例如:

<form>
    <input type='text' name='myText1' value='hello'/>
    <input type='text' name='myText2' value='world'/>
</form>
你的信息框会说:

myText1=hello&myText2=world
myData是要传递到$.post函数中的数据值

由于您是jQuery新手,我可能建议您尝试使用该函数。它有很多选择,但我一直认为它比$.post更简单易懂。以下是我如何使用它:

$.ajax({
    type: "POST",    //define the type of ajax call (POST, GET, etc)
    url: "my-ajax-script.php",   //The name of the script you are calling
    data: myData,    //Your data you are sending to the script
    success: function(msg){
        $("#result").html(msg);   //Your resulting action
    }
});

顺便说一句,不要忘记,为了使用jQuery serialize函数,所有输入都需要设置name属性,否则serialize函数将忽略它们。

数据是输入的序列化值。例如:

<form>
    <input type='text' name='myText1' value='hello'/>
    <input type='text' name='myText2' value='world'/>
</form>
你的信息框会说:

myText1=hello&myText2=world
myData是要传递到$.post函数中的数据值

由于您是jQuery新手,我可能建议您尝试使用该函数。它有很多选择,但我一直认为它比$.post更简单易懂。以下是我如何使用它:

$.ajax({
    type: "POST",    //define the type of ajax call (POST, GET, etc)
    url: "my-ajax-script.php",   //The name of the script you are calling
    data: myData,    //Your data you are sending to the script
    success: function(msg){
        $("#result").html(msg);   //Your resulting action
    }
});

顺便说一句,不要忘记,为了使用jQuery serialize函数,所有的输入都需要设置name属性,否则serialize函数将忽略它们。

我想他问的是数据输入是什么,而不是返回/响应是什么。@Jakobud叹气,我的响应被OP重新命名/澄清了,这听起来很有趣。你的否决票还有效吗?@Jakobud:我认为否决票是没有理由的。据我所知,aem指的是正确的事情。啊,好吧,我投否决票的唯一原因是将正确答案浮到堆栈顶部,因为OP似乎没有选择正确的答案。如何删除不带向上投票的向下投票?如果我能弄明白,我会把它删除。我想他问的是数据输入是什么,而不是返回/响应是什么。@Jakobud叹气,我的回答被OP的重命名/澄清抓住了,这听起来很有趣。你的否决票还有效吗?@Jakobud:我认为否决票是没有理由的。据我所知,aem指的是正确的事情。啊,好吧,我投否决票的唯一原因是将正确答案浮到堆栈顶部,因为OP似乎没有选择正确的答案。如何删除不带向上投票的向下投票?如果我能弄明白,我会删除它。我想OP是问响应数据是什么,而不是输入数据是什么。我想OP是问响应数据是什么,而不是输入数据是什么。