options.js - jquery ajax get doesn't work inside of a function

I am trying to do a jquery ajax get when user clicks submit in options.js b=
ut it won't work inside of a function.  The weird thing is, if I make it sy=
nchronous, it will work.  But if I make it asynchronous, nothing happens, n=
o pass or fail.  If I make it asynchronous and take it out of the function =
it works.

function submitOptions() {
  jQuery.ajax({
   url: "http://blah.com",
   dataType: 'json',
   timeout: 3000, // 3 seconds
   success: function(init){
    console.log("pass");
   },
   error: function(){
    console.log("fail");
   }
  })
}
0
quazimozi
8/11/2016 7:58:00 PM
mozilla.dev.extensions 5694 articles. 0 followers. Post Follow

2 Replies
437 Views

Similar Articles

[PageSpeed] 56

=D0=BF=D1=8F=D1=82=D0=BD=D0=B8=D1=86=D0=B0, 12 =D0=B0=D0=B2=D0=B3=D1=83=D1=
=81=D1=82=D0=B0 2016 =D0=B3., 2:58:02 UTC+7 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=
=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C quaz...@gmail.com =D0=BD=D0=B0=
=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
> I am trying to do a jquery ajax get when user clicks submit in options.js=
 but it won't work inside of a function.  The weird thing is, if I make it =
synchronous, it will work.  But if I make it asynchronous, nothing happens,=
 no pass or fail.  If I make it asynchronous and take it out of the functio=
n it works.
>=20
> function submitOptions() {
>   jQuery.ajax({
>    url: "http://blah.com",
>    dataType: 'json',
>    timeout: 3000, // 3 seconds
>    success: function(init){
>     console.log("pass");
>    },
>    error: function(){
>     console.log("fail");
>    }
>   })
> }

0
ivan
8/11/2016 9:35:59 PM
I may just move the ajax to background script and call it via sendMessage.
0
quazimozi
8/11/2016 10:26:44 PM
Reply: