[jQuery] Having a problems with $.post() and external .js files
Hi all,
Can someone help? I'm having a problem with $.post() and including
external .js files.
I include my jquery in the header of each page:
<script type="text/javascript" src="includes/common.js"></script>
I have a php file which includes a form [an external php file called
searchformbox.php]. Each time a <select><option> is changed in the
form, jquery handles the submit by doing a $.post() and sending all
the form variables back to searchformbox.php. The searchformbox.php
with the new form options is reloaded its <div> by using .html()
What I have found, is that if I don't re-include the external .js file
in searchformbox.php, the jquery does not trigger the second time a
<select><option> is changed.
The answer [it seems] is to re-include the external .js file in
searchformbox.php. However, this causes the jquery to be triggered
twice (obviously causing twice the number of mysql queries and a GET
to reload the common.js file).
I [think I] understand why the jquery is triggered twice, but I can't
understand how to stop it. It seems like a catch 22 problem... can
anyone help?
Thanks :)
Here's the jquery I use for the form resubmit [each <select> has the
class .selector]:
$(".selector").change(function(){
$("#loadingbox").show();
var brand = $('#brand').val()
var oldbrand = $('#oldbrand').val()
var model = $('#model').val()
var freegift = $('#freegift').val()
var minutes = $('#minutes').val()
var texts = $('#texts').val()
var contractlength = $('#contractlength').val()
var price = $('#price').val()
var phoneprice = $('#phoneprice').val()
var selectednetworks = [];
$('@name=network:checked').each(function() {
selectednetworks.push($(this).val());
});
$.post("searchformbox.php", {
'selectednetworks[]':selectednetworks, phoneprice: phoneprice, price:
price, brand: brand, model: model, freegift: freegift, minutes:
minutes,
texts: texts, contractlength: contractlength, oldbrand: oldbrand },
function(data){
$("#searchbox").html(data);
}
);
});