jquery - 页面上的多个 jquery ajax 不起作用

标签 jquery ajax colorbox

我在一页上有 2 个 ajax 请求。两者在不同的页面上都可以正常工作,但是当它们都在同一页面上时,其中一个会在第一个页面运行后停止工作。

我正在使用 Colorbox 插件来处理一个请求,效果很好。另一个是我自己组装的(我是 jquery 新手,所以很可能有错误),如果我先运行它,它就可以工作。但是一旦 Colorbox 被激活,它就会停止工作。

页面在这里:http://dev.thetram.net/times/test2.php以及下面的代码。

非常感谢您指出我出错的地方,谢谢!

<script type="text/javascript">
<!--
$(document).ready(function(){

$(function() {
$('#parkride').change(function () {

$.ajax({
    type: "POST",
 url: "http://dev.thetram.net/inc/parkingfinder_script.asp",
 dataType: "application/x-www-form-urlencoded",
 data: "Action=GetPR&Val=" + $("#parkride").val(),
 async: false,
 success: function(msg) {
     $('#output').html("<li>" + msg + "</li>");
 }
 });
return false;
    });
  });


$(function() {
//if submit button is clicked
$('form#frm_journeyplanner #submit').click(function () {

//get form values
var str = $("form#frm_journeyplanner").serialize();

$.ajax({
    type: "POST",
    url: "http://dev.thetram.net/inc/journeyplanner/jp_testscript.asp",
 dataType: "application/x-www-form-urlencoded",
    data: str,
 async: false,
 success: function(msg) {
  $('#results').html(msg);
  $.colorbox({inline:true, href:"#results", opacity:0.6, innerWidth:620, innerHeight:580, title:"Find tram times",
  onOpen:function(){  $("#results").show(); }, //make sure results show in the modal window
  onClosed:function(){ $("#results").hide(); } //stop results from displaying on the main page
   });
 }
 });
return false;
    });
  });

}); // end of doc ready
-->
</script>

最佳答案

尝试删除

async: false

线。这告诉 jQuery 同步运行请求,这会阻止浏览器直到请求完成。

关于jquery - 页面上的多个 jquery ajax 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4313318/

相关文章:

c# - colorbox + asp.net 按钮不会回发

jquery - 使用 jQuery animate 调整高度时 IE 边框困惑

jQuery - 有多个 $(document).ready(function() {}); 是不是很糟糕?

javascript - 使用ajax增加整数模型变量

jQuery、CSS 和兄弟选择器问题

javascript - Asp.net Masterpage 和 ContentPage JavaScript 函数错误

jquery - 将表单从 Colorbox iframe 提交到父窗口

javascript - 如何为此功能添加 3 秒延迟

javascript - 如何使用chart js或其他库绘制甘特图

Javascript 触摸事件故障