php - jquery ajax post - not working first time page loads -


i have ajax/jquery code in 1 of pages , problem i'm having doesn't work first time page loaded. if refresh page works no prob. work in firefox first time. variables i'm using ok i've alerted them out. don't success or error message. justr doesn't appear anything?

any ideas?

$('.window .request').click(function (e) {                 var itm = document.getelementbyid('txtitm').value;    var qty = document.getelementbyid('txtqty').value;   var msg = document.getelementbyid('txtmessage').value;   var op_id = document.getelementbyid('txtop_id').value;      $.ajax({     type: "post",     url: "do_request.php?msg="+msg+"&itm="+itm+"&qty="+qty+"&op_id="+op_id,     contenttype: "application/json; charset=utf-8",     datatype: "json",     success: function (msg) {       document.getelementbyid('div_main').style.display='none';       document.getelementbyid('div_success').style.display='block';       var row_id = document.getelementbyid('txtrow').value;       document.getelementbyid('row'+row_id).style.backgroundcolor='#b4e8aa';     },      error: function (xmlhttprequest, textstatus, errorthrown) {       alert('error submitting request.');     }    });  });  

it's hard determine problem might given information , sounds you've not tested page in consistent manner. seems there element on page affecting click event, opposed handler logic itself, there's no way tell. make sure binding click event after page ready:

$(document).ready(function(){   $("#uniquedomid").bind('click',function(){     // click handler logic   }); }); 

also, you're new jquery, 1 thing you're going want start looking @ various ways in jquery can improve life. everything. starters, you're going want start using:

$("#uniquedomid") 

instead of

document.getelementbyid("uniquedomid") 

and

$("#uniquedomid").val(); 

instead of

document.getelementbyid("uniquedomid").value 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -