Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

jquery extend with ajax call

Hi -

Don't know if this is possible but I would like to put and ajax call into an extend...

Much like below but it does not see to return any thing

 $.extend({
           getUVar: function () {
               $.getJSON('http://www.mydomain.com/somajaxcall', function (data) {
                return '123456'
               })
               
           } // end getUidVar
       });     //end ext


If I do this I get no issues

 $.extend({
           getUidVar: function () {            
                return '123456'              
           } // end getUidVar
       });     //end ext

If I do this I get no issues
  $.getJSON('http://www.mydomain.com/somajaxcall', function (data) {
               data= eval("(" + data+ ")");
               })

But as soon as I add them together then I get no return

What I am trying to do is make an ajax call with a single command so I can reuse it all through the site.

Thanks in advance
0
doctor069
Asked:
doctor069
  • 3
  • 2
1 Solution
 
varontronCommented:
Hi,

What does your call to the extension function look like?  Not sure if it's just copy/paste in the question, but your functions have different keys.  In your example code it's called getUVar, not getUidVar.

If that isn't the issue, try adding an arg to the success handler:

$.extend({
           getUVar: function (data) {

Open in new window


-Dave
0
 
doctor069Author Commented:
Sorry a cut and paste issue

I call it like this

alert($.getUVar())

 $.extend({
           getUidVar: function () {            
                return '123456'              
           } // end getUidVar
       });     //end ext

should be

 $.extend({
           getUVar: function () {            
                return '123456'              
           } // end getUidVar
       });     //end ext


0
 
varontronCommented:
ok, right.  i see you have the (data) arg there in the OP after all.  my bad.
0
 
varontronCommented:
Hi,

Assuming it's not a cross-domain thing (as you've indicated mydomain.com) the only thing that i can think of is that the request is returning malformed JSON.  Try changing 'getJSON' to 'get' and see what comes back.  or change it to 'ajax' and include an error handler.

I think getJSON fails silently when it's not JSON being returned.  

Dave
0
 
doctor069Author Commented:
Turned out the be a cross domain issue?

Thanks
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now