-1

I'm using greasemonkey with Firefox to alter what content is displayed when I visit a particular domain. One of the pages contains a dropdown with two elements, let's call them element0 and element1. Whenever it detects a switch from one to the other, it performs an ajax query that alters the page content depending on which one you've selected. So it looks something like this:

$(".dropdown").change(function(){

if($(this).val()=='element0'){
$.ajax({
    // fetch some html
   });
}

else{
$.ajax({
// fetch some other html entirely
});

I'm happy with what is displayed when element0 is selected - it's element1's associated content I want to alter. So I need a way to trigger my own userscript function only in the second case. I also somehow need it to execute only after the ajax query is complete of course. How do I do this?

I have some basic experience with programming, but know absolutely nothing about jquery, ajax, json etc etc. A friend helped me locate the above ajax for that page so that I could even post a meaningful question. Please bear my level of experience in mind, because I'd really really like to move forward with whatever knowledge/wisdom you guys can offer, but will only be able to do so if I understand it.

Many thanks!

EDIT: The above is javascript that the host is running. I accessed it by saving the page and looking around manually. I am writing userscripts on the client side to alter what my browser displays. So I want to write my own function that responds to their js in the way I described.

Katherine Rix
  • 672
  • 2
  • 8
  • 18

1 Answers1

-1

AJAX

In ajax you have a tow useful method, success & compleate

success: with execute if ajax request are work truth

complete: are work when finished ajax function, so you can use this method

example:

                    complete: function(){
                        // call another ajax, hide somthing, do any somthing
                    },

another example:

var all_data = {'user':txtuser,'pass':txtpass};
$.ajax ({ 

url:"ajax.php",
type:"post",
data:all_data,
beforeSend:function(){
// do somting before send a data
},
statusCode:{
404:function(){
                 $("#ma").html("Page not found");
              },
401:function(){  
                 $("#ma").html(".....");
              }

           },

success:function (data) {
$("#ma").html(data);// if sucsess
},

complete:function(){ // when complete
$("#user").hide(2000);
$("#pass").hide(2000);
$(".q").hide(2000);
}


});
Anees Hikmat Abu Hmiad
  • 3,460
  • 2
  • 19
  • 36
  • @ Anis thanks for your answer so far. Unfortunately, I don't think this will work. It looks like it's something I'd have to add to their ajax stuff, which I can't because it's on their server. I'll edit my question to make the situation clearer. – Katherine Rix Jul 10 '14 at 08:14