通过帖子发送ajax表单的值 [英] Sending values of a form with ajax via post

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

问题描述



<$ p $我试图在ajax中通过POST发送表单中的值,我如何捕获它们以发送它们,这是我现在在GET中的形式p> function test(ans_field_uuid){
var result =;
var url =ajax_pages / remove_answer_field_ajax.php
url + ='?uuid ='+ ans_field_uuid;
$ .get(
url,
function(data){
result = data;
}

.success(function( ){
if(result!=){
addTableRow('tb_add_field',result);
$('#ajaaxDiv')。html(result);
}
})
.complete(function(){
$('#img_create_subcat')。hide();
$('#dialog')。dialog('close' );
})
.error(function(){
alert('发生错误');
});
返回false;
}


解决方案

/ p>

  $。ajax({
类型:POST,
url:some.php,,
data:{name:John,location:Boston}
})。done(function(msg){
alert(Data Saved:+ msg);
});

数据:名称和位置是您的POST变量。
您可以使用

  $ _ POST [name] $在some.php中获取POST变量b $ b  

等于John



如果你想要收到一些东西,然后像你好。
在some.php里面

  echoHello; 

它会作为变量msg

im trying to send values in a form via POST in ajax, how do i capture them in send them, this is wat i have now while in GET

    function test(ans_field_uuid){
        var result = "";
        var url="ajax_pages/remove_answer_field_ajax.php"
        url += '?uuid=' + ans_field_uuid;
        $.get(
        url,
        function (data) {
            result = data;
        }
    )
        .success(function () {
            if (result != "") {
                addTableRow('tb_add_field', result);
                $('#ajaaxDiv').html(result);
            }
        })
        .complete(function () {
            $('#img_create_subcat').hide();
            $('#dialog').dialog('close');
        })
        .error(function () {
            alert('An error has occurred.');
        });
        return false;
    }

解决方案

since you already use jQuery

$.ajax({
  type: "POST",
  url: "some.php",
  data: { name: "John", location: "Boston" }
}).done(function( msg ) {
  alert( "Data Saved: " + msg );
});

data: name and location are your POST variable. You can fetch the POST variable in this example in some.php with

$_POST["name"]

which equals "John"

If you want to receive something then like "Hello". Inside your some.php

echo "Hello";

and it will be send to your ajax function as response in your done function as variable msg

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

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