Home Top Projects Tutorials Articles Submit Project
 
  • .NET Frameworks
  • Java Frameworks
  • PHP Frameworks
  • Ruby Frameworks
  • Other Frameworks
  • Cool AJAX sites
  • Ajax Resources
  • Ajax Tools
  • JavaScript frameworks
 
     
    • Rounded Corner Box Using Div and CSS
    • Simple AJAX is getting advanced
    • How to use JavaScript libraries like jQuery or Prototype with AJAX.NET
    • Synchronous Ajax with jQuery
    • When is your page ready?
    • Integrating Direct Ajax into the Enterprise Environment
    • Defensive AJAX and AJAX retries in jQuery
    • Creating a Dynamic Poll with jQuery and PHP
    • The problem with innerHTML
    • Creating an Autosuggest Textbox with JavaScript, Part 3
    Home » Tutorials » Synchronous Ajax with jQuery

    Synchronous Ajax with jQuery

    Earlier, I had a problem getting the result of my Ajax call and operating on it without doing an asynchronous callback. What I wanted to do was assign the result of my ajax call to a variable so I could parse through it and return a result. After a little searching, I found this result.

    1 var result = $.ajax({url: "/my_relative_path", data: {param1: value, param2: value}, async: false}).responseText;

    Please note that because responseText returns a string, if your Ajax response includes JSON formatted objects, you need to use eval to convert them to objects.

    2 var result_objects = eval(result);

    In my case, I was returning a list of parameter id’s that matched some form fields I need to to change the style of. So, I created a for loop and looped over the objects in my array.

    source: charlesmaxwood

    Copyrights Reserved AjaxProjects.com 2006-2013, Powered by Enozom - Mobile Development Company -Privacy Policy