[英]AJAX get query not causing page to load
我使用以下代码来检测表单选择中的更改,然后发送带有数据的AJAX get请求。
$("#configset").change(function(){
$.ajax({
method: "get",
url: "/bmcfg/index.php", // This is the url that will be requested
data: {"configset": $("#configset").val(),
"configupdate": "update"
},
success:function()//we got the response
{
// alert('Successfully called:'+ $("#configset").val());
},
error:function(){alert('Exeption:');}
});
});
在服务器端,我使用PHP来处理请求。
if ((isset($_GET['configupdate']) and $_GET['configupdate'] == 'update'))
{
echo 'get received:'.$_GET['configupdate'];
include project.html.php
}
我从未在新页面上看到回声线? 我只是希望PHP加载新网页而不必将其作为数据发送回ajax。
将参数添加到从PHP获取值的函数中:
success:function( data )//we got the response
{
alert( data ); // <========== VALUE ECHOED FROM PHP.
}
解决方案显然不是使用AJAX,而是使用表单并在检测到更改时提交表单。 AJAX将在AJAX中发送和接收数据。 因此,服务器端PHP脚本发送的数据也将被发送到AJAX。
这可以通过使用JQuery使用表单提交来修复。
$("#selectid").change(function(){ <------ this is the select tag "id"
$("#formid").submit(); <---- this is the form tag "id"
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.