How to get jquery to perform a synchronous ajax request

request ajax synchronous a perform to jquery get to How

I had the problem that i dont want to do a asynchronous request with jquery ajax. So i did search for a real solution for me.

I also had the difficulty that it is a crossdomain call. So i have to use jsonp as well.

The solution i have found is as follow:

  _getObj = function () {
                var data = JSON.parse($.ajax({
                    type: "GET",
                    contentType: "application/json; charset=utf-8",
                    url: url,
                    async: false,
                    dataType: "json"
                }).responseText);

                var m = new foo();
                m.gesamteuros = data.d.foo;
                return m;
            },

Important here is the assignment, the data variable gets the ajax response.

Next is the return obj  part in the function.

As a result it finally works for me.



Saving the comment

Add comment

Required Please choose another name

biuquote
  • Comment
  • Preview
Loading

192.168.15.197