$ .load内部的表单没有正确发布 [英] Form inside of $.load not posting correctly

查看:92
本文介绍了$ .load内部的表单没有正确发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  Readthis =MonsterRequest。这是我得到的,基本上一个按钮被点击并执行以下代码: php?id =<?php echo $ _REQUEST ['id'];?>& Mon =; 
TestVar = TestVar.replace(/ \s / g,);
Readthis = Readthis + htmlencode(TestVar);
$('#CenterPiece')。load(Readthis);

除了传递给Monsterequest.php时,所有内容似乎都可以正常工作,传递到它自己和页面基本上重新加载它是自我,因为它被传递到主要的父母......(我不确定它是否是,但monsterrequest.php似乎工作完全罚款自己但是当它加载它不起作用因为我的意图是所有的和我完全难住。我基本上想发布的数据没有重新加载页面。



Monsterrequest.php:
http://pastebin.com/fiFjjBZg

解决方案

如果你已经知道这一点,请原谅我,但如果你不知道的话: Ajax将数据发布到外部php文件,它处理它收到的数据,然后发回一个答案。它看起来像这样:

FILE#1:

 < html> 
< head>
< script src =// ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js\"> ;</script>
< script type =text / javascript>
$(document).ready(function(){
$('#Sel')。change(function(){
var opt = $(this).val();
var someelse ='Hello';
var more_stuff ='Goodbye';
$ .ajax({
type:POST,
url:receiving_file.php ,
data:'selected_opt ='+ opt +'& something_else ='+ someelse +'& more_stuff ='+ more_stuff,
success:function(data){
alert('这被发回:'+ data';
}
});
});
});
< / script>
< / head>
< body>

< select id =Sel>
< option value =Song1>默认值< / option>
< option value =Song2>打破< / option>
< option value =Song3>时间< / option>
< option value =Song4>金钱< / option>
< option value =Song5>碟片秘密< / option>
< / select>

文件#2:receiving_file.php

 <?php 
$ recd = $ _POST ['selected_opt'];
echo'您选择了:'。 $ RECD;


Well here's what I got, basically a button is clicked and the following code is executed:

    Readthis = "MonsterRequest.php?id=<?php echo $_REQUEST['id']; ?>&Mon=";
    TestVar = TestVar.replace(/\s/g, "");
    Readthis = Readthis + htmlencode(TestVar);
    $('#CenterPiece').load(Readthis); 

Everything seems to work as intended except for when passed to Monsterequest.php, the post isn't being passed onto it's self and the page basically reloads it's self as it was being passed onto the main parent...(I was unsure if it was but monsterrequest.php seems to work perfectly fine on it's own however when loaded it doesn't work as intended at all and I'm completely stumped. I basically want to post data without having the page reloaded.

Monsterrequest.php: http://pastebin.com/fiFjjBZg

解决方案

Are you familiar with AJAX? Forgive me if you know this already, but in case you don't:

Ajax posts data to an external php file, which processes the data it receives, and sends back an answer. It looks like this:

FILE #1:

<html>
    <head>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                $('#Sel').change(function() {
                    var opt = $(this).val();
                    var someelse = 'Hello';
                    var more_stuff = 'Goodbye';
                    $.ajax({
                        type: "POST",
                        url: "receiving_file.php",
                        data: 'selected_opt=' + opt + '&something_else=' +someelse+'&more_stuff='+more_stuff,
                        success:function(data){
                            alert('This was sent back: ' + data);
                        }
                    });
                });
            });
        </script>
    </head>
<body>

<select id = "Sel">
    <option value ="Song1">default value</option>
    <option value ="Song2">Break on through</option>
    <option value ="Song3">Time</option>
    <option value ="Song4">Money</option>
    <option value="Song5">Saucerful of Secrets</option>
</select>

FILE #2: receiving_file.php

<?php
    $recd = $_POST['selected_opt'];
    echo 'You chose: ' . $recd;

这篇关于$ .load内部的表单没有正确发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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