Tuesday 15 January 2013

javascript - Making a JQuery ajax request conditional -



javascript - Making a JQuery ajax request conditional -

i skip piece of code if preconditions not met, want move code between parenthesis in function. allowed? don't understand how syntax works.

$.ajax({ type: "post", url: urlappend, data: json.stringify(xxx), contenttype: "application/json; charset=utf-8", datatype: "json", processdata: false, success: function (result) { if (canceled) { return; } //long code } //long code 2 }, error: function (request, error) { alert('ppp'); } });

place $.ajax phone call function, wrap phone call function in conditional expression:

function makerequest(){ $.ajax( ... ) } if ( some_condition ){ makerequest(); }

keep in mind using variables within ajax callback (namely canceled variable). you'll have create variable available function.

javascript jquery ajax

No comments:

Post a Comment