setting ajax response to a variable

Yesterday I was working on a small task of validation through jquery ajax, I was comparing two dates through ajax and then needs to set an variable on success, which I can use further in the same function but it was not working as per requirement. My code was like

$.ajax({
type: "POST",
url: 'test.php',
data: datastr,
success: function(res) {
result = res;
}
});

This code was not giving me “result” variable and I want to use it further in next ajax request, then I searched and found as the request is asynchronous it will not work and I made the request synchronous, like

var result = '';
$.ajax({
type: "POST",
async: false,
url: 'test.php',
data: datastr,
success: function(res) {
result = res;
}
});

alert(result); // use it here

Now I can use result any where in this function.

Links

phpcamp pune 2011: A gathering of php enthusiast

Twitter

  • now what will happen to our :(, congratulations @adii n team RT The WP App Store is now live!
    http://t.co/GX4fVbAL
    2012/05/15 22:29
  • Without Internet at office for whole day, thanks to BSNL.
    2012/05/14 23:20
  • Back after luch for #punebloggersmeet
    2012/05/05 14:42
  • New faces, good stories from various bloggers at #punebloggersmeet , yes intro is still happening
    2012/05/05 13:02
  • So @sandygautam is here.. And he looks different from his pic :) #punebloggersmeet
    2012/05/05 12:45

Pages

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 Buy Prednisolone Pharmacy Prednisolone Best Price Buy Erythromycin In The Us No Prescription Erythromycin Online Pharmacy Sydney Australia Maxalt Fast Canadian Pharmacy Cheap Buy Vasotec Online Cheap Prevacid No Prescription Uk Prevacid Mail Order Diflucan For Sale Canada No Prescription Drug Store Cheap Phenergan In Australia Phenergan Mail Order No Prescription Meds Viagra Shipped From Canada Online Pharmacy Solutions Buy Professional Plasma Tooth Whitening Kit Online Buy Aricept Cheap Online Free Viagra Samples Buy Premature Ejaculation Cure In Edmonton Canada Discount Prices Buying Wellbutrin SR In Toronto Canada Best Prices Buy Cialis Super Active Online Cheap Free Viagra Samples Canadian Pharmacy Meds Buy Lumigan Eye Drops Online Cheap Nitroglycerin Online No Prescription Discount Prices Sublingual Viagra No Prescription Uk Sublingual Viagra Mail Order Online Pharmacy Germany Wellbutrin Online Cheap Yasmin Online Without Prescription In Canada Fast Online Pharmacy In The Uk Buy Neurontin Online Cheapest Male Enhancement Oil Canada Free Viagra Sample Pills Fucidin Edmonton Canada No Prescription Fucidin How To Get Cefixime Canada Order Online Here Brand Amoxil Uk Pharmacy Brand Amoxil Shipped From Canada Buy Quick Melt Melatonin Online Nz Quick Melt Melatonin Mail Order Tretinoin Cream Price Per Pill Tretinoin Cream Online Prices Simplicef In Poland Simplicef Shipped From Canada Can You Buy Testosterone Booster Strips Usa Yes Here Online Phenergan Shopping Phenergan Online Fast Shipping Buying Zyban In Usa Free Viagra Sample Pills Sublingual Viagra Best Price Uk No Prescription Uk Sublingual Viagra