$.load 中的表单未正确发布

编程入门 行业动态 更新时间:2024-10-10 19:27:10
本文介绍了$.load 中的表单未正确发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

好吧,这就是我得到的,基本上是单击一个按钮并执行以下代码:

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);

除了传递到 Monsterequest.php 之外,一切似乎都按预期工作,帖子没有传递给它自己,页面基本上重新加载它自己,因为它被传递到主要父级......(我是不确定是否是,但 Monsterrequest.php 似乎在它自己的情况下工作得很好,但是加载时它根本无法按预期工作,我完全被难住了.我基本上想在不重新加载页面的情况下发布数据.

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:pastebin/fiFjjBZg

Monsterrequest.php: pastebin/fiFjjBZg

推荐答案

您熟悉 AJAX 吗?如果您已经知道这一点,请原谅我,但如果您不知道:

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

Ajax 将数据发布到一个外部 php 文件,该文件处理它接收到的数据,并发回一个答案.它看起来像这样:

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

文件 #1:

<html> <head> <script src="//ajax.googleapis/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>

文件 #2:receiving_file.php

FILE #2: receiving_file.php

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

更多推荐

$.load 中的表单未正确发布

本文发布于:2023-10-10 22:11:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479905.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   正确   load

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!