want to do multiple div elements hide using ajax helper on getting response.but not using like this complete=>element.hide(div1),element.hide(div2),element.hide(div3),element.hide(div4)
If your question is how to hide multiple elements after an ajax response, you'll need to set up some javascript to do this. It depends on the javascript library you're using, but basically, you'll set $options['complete'] to something like "doStuffAfterComplete()".
Then, create a javascript function, like you normally would with your js library of choice. Using jQuery? Then it would be something like:
function doStuffAfterComplete(data) {
$('div.whatevs').hide();
}
Related
I Would like to know if there is a possibility to modify an external js file via ajax post, for example:
Into my external js file i've got a variable :
var color;
So i would like my users to be able change the value of this variable by typing the HEX code into an input text form.
So when the type and press submit button to grab this value and post it to external js file and modify the variable.
I want something like this:
var colorVal = $('input').val();
$.post("external-file-js.js", {color: colorVal}, function(result){});
In external js file something like:
var color = $.get(colorVal); // HERE i dont know how to grab the value
$('body').css('background-color',color);
Thank you :)
I need to understand the use case you are intending in order to provide a full answer. If all you are attempting to do is change the background color, why do you need to run an AJAX post at all? Why not just change it?
In extenal.js (which is included in html body):
function changeColor(color) {
$('body').css('background-color',color);
}
Then you bind the following event to the input:
$('input').change(function () {
// Though you may want to perform validation first.
changeColor($(this).val());
});
The only problem is if you need to change it long term, for multiple users. Then you would need to store the value server side (with a post and some type of CRUD system, in which case, check out JSON/JSONP)
It can be done. You would have to use some back-end code to rewrite your JS file. You would then need to remove any binds and use a script to reload your js document on the fly. Here is an example of loading JS on the fly. http://www.philnicholas.com/2009/05/11/reloading-your-javascript-without-reloading-your-page/
I am not sure why you would do this. I would just rework my JS file so I can avoid this mess.
I want to update my MVC3 view Using Ajax,
My Code is here Here
Please tell me how i'll add Ajax in my code to update a content of HTML table
The basic outline would be:
Client Side
Call a JavaScript function from your update button.
Within the JavaScript function, use jQuery to make an AJAX call to
an action method on the server.
On success, use the returned JSON to generate the updated HTML and update your containing div, probably using a jQuery selector and the html() method.
Server Side
Create an action method with a return type of JsonResult.
Retrieve whatever data it is you need from wherever.
Return the data using return Json(myData) (you may find it easier to use the JSON.NET Newtonsoft library to get more control over serialising your objects into JSON).
Have a Google into these various steps, completely overhaul your code and see how you get on.
Ok, I have written some classes/functions that allow me to bind specific behaviors to certain DOM elements. I want to group all the behaviors for certain elements together, so I create a plugin/function that uses delegate to set up all the functionality I want. As an example, say I want all of my forms to pass through a validation check before submitting, and I also want some text to appear when someone exists an input field (these are just examples). So I've written my own form plugin to automatically handle all these capabilities. It might look something like this:
jQuery.fn.myFormPlugin = function(options){
this.each(function(){
$(this).submit(function(event){
blah blah blah...
});
$(this).children("input").bind("focus",function(){
blah blah blah...
});
});
}
And then when the page loads, I simply invoke it via:
$("form.mySpecialForm").myFormPlugin();
All that works great. But now say I am loading some of these forms via Ajax. How can I automatically bind the plugin to all forms, whether loaded normally or via ajax? I don't believe I can use bind, delegate or live as these can't be associated with a "load" event, so I am stuck. I suppose I could call the plugin as part of the success callback in the ajax load, but then I would have to do that individually with each ajax load.
And I have other plugins to use in a similar way for other DOM elements, like tabs, accordions, etc., so I am looking for something of a holistic approach.
Thanks very much in advance.
You can add custom events - and then trigger those custom events when you need to.
a walk through example: http://www.reynoldsftw.com/2009/04/custom-events-in-jquery-open-doors-to-complex-behaviors/
I'm building a custom module in Drupal 6 which display a block with a form and some other elements like text and images. When it's submitted, using AHAH, some logic takes place in PHP and then the result is passed to JQuery which will update the elements in the block. Mainly a few images and some text.
I can't wrap my head around using AHAH, but it seems like that's what I'm supposed to be using. Currently I have my form with the submit button implementing '#ahah' and the path is set to a path defined in my menu hook. The menu hook passes it to the callback function which performs the logic then I'm at a dead end. How do I get the results to jQuery?
Any ideas?
Howie
Figured out a solution using: http://drupal.org/project/examples.
i am using cakephp in my project. in this at one section i need to update the particular row onclick of the image. using ajax. i used mootools as javascript library. so please help me how could i do this.
thanks in advance
Simply speaking:
Create a CakePHP controller action that performs the row update.
Determine the URL of the controller action you just created. (ie. /controllername/actionname)
Determine if you need to do a GET or POST request to this URL for it to work.
Put code in your view that attaches an "onclick" event that makes and AJAX (GET/POST) request to the above controller.
CakePHP has a javascript helper that traditionally produced Prototype code, but in v1.3 it is now able to produce code for other Javascript frameworks (such as Mootools, jQuery, etc.)
However, many suggest writing your javascript in javascript (eg. actually using the Mootools framwork), rather than writing your javascript in PHP (like using CakePHP's helper to produce Mootools code).
Either way, in your view you need to have something like: <?php echo $js->link(.. or <script>Moo.. or <a onclick="Moo.. to attach your Javascript to that link.
You may also wish for your controller action to return some sort of response indicating whether or not the row update failed or succeeded. In that case you need to make sure the CakePHP controller action you are calling has a view that outputs this. JSON seems to be the ideal format for this (eg. { success: true }), but you need to remember to turn off Cake's debug output. This response can be captured into a variable by your Mootools code where you can decide what to do with it (eg. displaying an error).
As i know most programmer work with protype.js library.
i am giving you link see
go to there