简体   繁体   English

AJAX表单发送数据,PHP表单不接收数据

[英]AJAX form sending data, PHP form not receiving it

I had this working earlier, but now it doesn't seem to want to pick up the data. 我之前已经完成了这项工作,但现在似乎不想提取数据。 It's possible something changed when I was trying to make it stop refreshing the page. 当我试图使其停止刷新页面时,可能发生了某些变化。

The form submits, but only for certain links. 表单提交,但仅适用于某些链接。 However the data gets sent across as normal. 但是,数据正常发送。 It's extremely strange. 非常奇怪。

This is the page the data is being sent to. 这是数据发送到的页面。 Right now it just accepts the data and posts it for testing. 现在,它只是接受数据并将其发布以进行测试。 "Text" shows but nothing else. “文本”显示,但没有其他显示。

<?php

$ship_id = $_POST['transfer_ship'];
$char_id = $_POST['transfer_character'];
$pos_id = $_POST['transfer_position'];
$requested_by = $_POST['transfer_player'];

echo 'Success';
echo $ship_id;
echo $char_id;
echo $requested_by;
echo $pos_id;
echo $char_owner;
echo 'Text';

This is the form it's being sent from. 这是它发送的形式。 It's part of a PHP UL series that's running. 它是正在运行的PHP UL系列的一部分。 For the first result, the jQuery fires, I get the "Success" alert. 对于第一个结果,jQuery触发,我得到“成功”警报。 For any of the other li links the data apparently gets sent (I use the F12 dev tools in Chrome, under Network, to see the header) but the page above either doesn't receive it or doesn't do anything with it. 对于其他任何li链接,数据显然都已发送(我在网络下的Chrome中使用F12开发工具来查看标题),但是上方的页面无法接收或不执行任何操作。

jQuery: jQuery的:

<script type="text/javascript" src="../fancybox/jquery.fancybox.js?v=2.1.3"></script>
<script type="text/javascript">
$(document).ready(function() {
    $(".fancybox").fancybox();
});
</script>
<script src="http://malsup.github.com/jquery.form.js"></script> 
<script> 
    // wait for the DOM to be loaded 
    $(document).ready(function() { 
        // bind 'myForm' and provide a simple callback function 
        $('#transfer').ajaxForm(function() { 
            alert('Success!');
        }); 
    }); 
</script> 

Form and UL: 形式和UL:

<ul>
<?php
        while(list($key, $val) = each ($arrayresult))
        {

            echo '<a href="#inline' .$val. '" class="fancybox"><li style="padding: 2px; margin: 0px; list-style: none;">';
            echo '<img src="../images/profilepics/'.$charpic.'" style="float: right; padding-left: 10px; width: 40px;" />';
            echo '<h2>'.$val.' Position</h2>';
            echo '<p>Click here to apply for this position.</p>';
            echo '</li></a>';

            echo '<div id="inline' .$val. '" style="display:none;">';
            echo '<h1>Request Character Transfer</h1>';
            echo '<hr>';
            echo '<form id="transfer" action="TransferRequest.php" method="post">';
            echo '<label for="transfer_character">Character to Transfer</label>';
            echo '<select id="transfer_character" name="transfer_character">';
            echo '<option value="">Select Character</option>';

            $request_character_query = "SELECT * FROM character_database WHERE character_active ='1' AND user_id = $user_id ORDER BY character_firstname DESC";
            $request_character_result = mysqli_query($mysqli, $request_character_query);

            /*** loop over the results ***/
            foreach($request_character_result as $charrow)
            {
              /*** create the options ***/
              echo '<option value="'.$charrow['character_id'].'">'. $charrow['character_firstname'] . " " . $charrow['character_surname'] . '</option>'."\n";
            }
            echo '</select>';
            echo '<p>Applying for the '.$val.' position on the '.$shipname.'</p>';
            echo '<p>If this is correct, please submit below</p>';
            echo '<input type="hidden" value="'.$val.'" name="transfer_position">';
            echo '<input type="hidden" value="'.$ship_id.'" name="transfer_ship">';
            echo '<input type="hidden" value="'.$user_id.'" name="transfer_player">';
            echo '<input value="Submit Request" type="submit" class="styled">';
            echo '</form>';
            echo '</div>';
        }
    ?>
</ul>

I figured it out! 我想到了! I have my htaccess file removing the .php extension, but I had .php on the redirect link for ajax. 我的htaccess文件删除了.php扩展名,但是在ajax的重定向链接上有.php。 So it was hitting the .php page then redirecting WITHOUT the POST data. 因此,它点击了.php页面,然后在没有POST数据的情况下进行了重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM