Javascript 带有结果处理程序的简单Ajax调用不起作用
我得到了这个JS:Javascript 带有结果处理程序的简单Ajax调用不起作用,javascript,php,ajax,post,google-distancematrix-api,Javascript,Php,Ajax,Post,Google Distancematrix Api,我得到了这个JS: <script> jQuery(document).ready(function(){ // we wait until DOM is ready jQuery('#veranstort').change(function(){ // fire when input is filled origin = "55767 Schwollen"; destination = "13509 Berlin"; jQ
<script>
jQuery(document).ready(function(){ // we wait until DOM is ready
jQuery('#veranstort').change(function(){ // fire when input is filled
origin = "55767 Schwollen";
destination = "13509 Berlin";
jQuery.ajax({ // we build the AJAX request
method:"POST",
url:"index.php?option=com_rsform&formId=6&action=ajax",
data: {origin, destination},
success: function(results) {
console.log("results: " + results);
}
});
});
})
</script>
这已经奏效一段时间了,但现在不行了。我无法访问php中的目标值或原点值。。我做错了什么?脚本文件没问题。请更改ajax文件条件
$action = $_GET['action'];
if ($action == "ajax") { // if condition is met, run the script
//// Here process your code
}
错误来自URL中缺少的
/
。它被重定向,并且POST数据在这个过程中丢失
正确的URL:
url:"/index.php?option=com_rsform&formId=6&action=ajax"
试着像这样发送数据:{“origin”:origin,“destination”:destination},。您尝试将数据作为不带键的对象发送。基本上,您发送的是
{“55767 Schwollen”,“13509 Berlin”}
,它既不是propper对象,也不是数组。但在PHP中,您尝试访问不存在的键,如$\u POST['origin']代码>。不确定这以前是如何工作的。@honkalonkaloooohh-呃,不。你似乎在现代JavaScript方面有点落后。这个问题的语法很好。我能想到的唯一一件事是,如果您在某个地方有一个ajaxSetup
调用破坏了数据的发送方式,那么可能会给出您描述的结果。但这不是问题所在。您需要提供一个。当Ajax请求发送时,您是否可以发布请求头的屏幕截图,如果请求头中有数据对象,假设您使用的是RSform组件,Joomla组件中肯定会出现问题。表单数据提交:是,可能是rsforms的问题。他们说问题出在访问目的地和来源地,而不是操作。该屏幕截图似乎与您的答案根本没有关系。在ajax文件中,我返回了Request POST值。在控制台中会显示post值。这意味着您无法重现问题。@VinothRaja-如前所述,您建议的更改不会影响问题。如果他们输入了,那么问题将是“PHP从未输入If语句”,而不是“PHP确实输入了If语句,但POST值为null
”
url:"/index.php?option=com_rsform&formId=6&action=ajax"