Hook and modify ajax request

I am a new jQuery. I use a closed framework that allows me to add code but not change some of these behaviors. To add functionality, I need to connect to a specific Ajax request and redirect it to my URL (so that I can change the data there and be a proxy) or change the request parameters on the client side.

Is this possible with jQuery? And if so, how?

The source event is fired after updating the input text field.


Update:

After further inspection, it seems that the text field is controlled using the JQuery Autocomplete plugin. I am trying to translate the words returned from this ajax request. Basically, the user enters text in one language, and I want to translate it into English (the translation itself is not a problem), so autocomplete will use English words, and then I want to translate from English to the original language to be displayed in the text box and the hanging div .

+6
jquery ajax proxy
source share
5 answers

I used the jQuery autocomplete plugin to do something similar, although not in the scenario where I am dealing with a "closed structure".

You can easily accomplish what you want using the .setOptions () method for an autocomplete object after its initialization. So your code would look something like this (untested! Pseudocode!):

$(autoCompletedField).setOptions({ formatItem: function(resultsRow, resultPosition, totalResults, inputWord) { // translate your menu items to be displayed in the drop down menu here // perhaps extend jQuery to handle $.translate(inputWord) ? return "<li>"+translatedWord+"</li>"; } }).result(function(event,selectedItem){ // optionally do something more when the user selects one of those items here // translate the selectedItem back to another language? i dont know. return translatedItem; }); 

check options: http://docs.jquery.com/Plugins/Autocomplete/autocomplete#url_or_dataoptions

+5
source share

I don’t think there is a simple solution to what you are trying to do, as the XMLHTTPRequest object is pretty closed for security reasons.

If you're lucky, the part that executes the AJAX request breaks down into a function that you can overwrite or override with the prototype object.

If not, you are probably better off disabling the text field change event.

In jQuery:

 $('#textboxid').unbind(); $('#textboxid').change(function () { $.ajax({ url: 'http://yourwebservice', data: {}, //the data to send to your webservice success: function (data) { //do your magic }; }) }); 
+3
source share

Have you looked at the observer pattern in javascript? I created an example on my blog. It can help you.

http://www.versomas.com/dannyg/post/Observer-pattern-in-Javascript.aspx

+1
source share

Use the jquery plugin to translate text. I used it very successfully to translate text in the past: http://code.google.com/p/jquery-translate/

0
source share

Can you look at the implementation of your code in the "beforeSend" AJAX request?

0
source share

All Articles