所以我是新的,使用jQuery .post(),但是我不使用之前尚未使用的方法。

当单击按钮时,我正在尝试发布两个隐藏的输入值:

$('#button').live('click', function() {
    $.post('export_file.php', { group: form.group.value , test: form.test.value },
    function(output)    {
        $('#return').html(output).show();
    });
});
.

我已经测试了按钮事件成功触发,目前我在export_file.php中尝试做的所有内容都会回声。

这是我的形式:

<form name="form">
<input type="hidden" name="group" value="<?echo $group;?>">
<input type="hidden" name="test" value="<?echo $test_id;?>">
<input type="button" class="Mybutton" id="button" name="btnSubmit" value="Export Results">
</form>
.

我在原始页面上有div:

<div id='return'></div>

export_file.php:

<?php

echo "whatever, something!";

?>
.

任何人都可以指出我错了的地方。非常感谢

有帮助吗?

解决方案

Fix this line:

$.post('export_file.php', { group: form.group.value , test: form.test.value },

Change it to something like this:

var group_val = $('input[name="group"]', 'form[name="form"]').get(0).value;
var test_val = $('input[name="test"]', 'form[name="form"]').get(0).value;
$.post('export_file.php', { group: group_val , test: test_val },

Fiddle: http://jsfiddle.net/maniator/cQ2vZ/

其他提示

Try:

$('#button').live('click', function() {
    $.post('export_file.php', { group: $("input[name='group']").val() , test: $("input[name='test']").val() },
    function(output)    {
        $('#return').html(output).show();
    });
});

I've added ids to your form elements in your HTML:

<form name="form">
    <input type="hidden" name="group" id="group" value="<?echo $group;?>">
    <input type="hidden" name="test" id="test" value="<?echo $test_id;?>">
    <input type="button" class="Mybutton" id="button" name="btnSubmit" value="Export Results">
</form>

Then amended the jQuery to get the values from these fields by ID, and use these in the parameters of your AJAX call:

$('#button').live('click', function() {
    var groupValue = $("#group").val();
    var testValue = $("#test").val();

    $.post('export_file.php', { group: groupValue , test: testValue },
    function(output)    {
        $('#return').html(output).show();
    });
});

try this one

$('#button').live('click', function() {
    var group_val = $("input[name='group']").val(); // gets the value of hidden field with the name group
    var test_val = $("input[name='test']").val(); // gets the value of hidden field with the name test and store it in test_val variable
    $.post('export_file.php', { group: group_val  , test: test_val  },
    function(output)    {
        $('#return').html(output).show();
    });
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top