Multiple jquery ajax on page not working

I have 2 ajax requests on one page. Both work fine on separate pages, but when they are on the same page, one stops working after the first start.

I use the Colorbox plugin for a single request, and this works great. The other one I built myself (I'm new to jquery, so it may have errors) and works if I run it first. But as soon as Colorbox is activated, it stops working.

The page is here: http://dev.thetram.net/times/test2.php and the code below.

It would be very helpful to understand where I am going, thanks!

<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>
+3
source share
3 answers

, .

ajax HTML- ( DIV) id = "output" , ajax- , DIV, UL, .

? , Google Chrome. , $( "# output" ) ( ) "" UL , , ajax, , DIV, ajax DIV id = "output" .

- $( "# output" ), id = "output" . UL , , .

, ajax:

$('ul#output').html("<li>" + msg + "</li>");
0

async: false

. jQuery, , , .

+2

You did not say which script is not working.

I assume it is attached to #parkride. If so, then for me it works fine in Chrome 9 (dev).

0
source

Source: https://habr.com/ru/post/1777645/


All Articles