문제
그래서 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
에서 수행하려는 모든 것이 echo 뭔가에 @ 입니다.
여기 내 형식이 있습니다 :
<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 },
다른 팁
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();
});
});
제휴하지 않습니다 StackOverflow