Is it possible to send a form and a html request with same Event by Mootools? - ajax

$('submitbutton').addEvent( 'submit', function(e){
e.stop();
$('fuss').send();
req2.send();
});
trying to get this working but not sure if it is possible and had no success so far.
Mootools docs doesnt helped me either.
Will the multiple usage of .send() work?
Do i have to specify the data beeing send for the html request or does it take automatical the data beeing send by the form ?

It's in the documentation: http://mootools.net/docs/core/Request/Request#Element:send
This shorthand method will do a request using the post-processed data from all of the fields.
You can do as many requests in a specific event as you wish, as long as they're all asynchronous.
In your specific example it would seem you want to do two requests using two different methods, one with setting up a new Request class manually and the second doing it via the Element Method.

Based on your last comment, I wrote a little example in jsFiddle.
Basically I think you don't need two request for your goal. Just override onRequest method to update the html.

Related

In which scope my ajax data send from view to handler is stored in coldbox

Please let me know answer if any one knows about it.In which scope my ajax data send from view to handler in coldbox
When you're making an ajax POST, it gets treated as a brand new request. This means you'll need a separate route and handler for that request.
Within your new handler (let's call it /handlers/data.cfc) you'll want to format your response appropriately for your code. ColdBox comes with some nifty tools to help you do this. One way would be to use renderData() within your handler or view.
Rough example:
event.renderData( type="json", data=yourData );
Once set up correctly, the ajax calling code should receive the formatted data from your new handler as expected.
Side note: I recommend including code samples when asking questions on StackOverflow. It will help those that want to provide assistance understand exactly what you are trying to do.

How should I update a component and non-component from an AJAX call?

Sorry if the question is confusing but I am just getting started with React. Basically, I am looking to start adding individual components to an existing website. Currently, when the page loads there are a couple of AJAX requests that update different parts of the page with jQuery.
For example, I make an AJAX request that is called every 30 seconds to get AccountInfo and when it returns a response, I update two separate parts of the page, let's call them AccountPanel and SideBar.
Question #1
If I were to create a component for the AccountPanel, should I make the AJAX request when the component mounts and continue to use jQuery to update the SideBar in there?
Question #2
Or is it better to create components for both and pass the AJAX response as props?
ReactDOM.render(<AccountPanel />, document.getElementById('accountPanel'));
ReactDOM.render(<SideBar />, document.getElementById('sideBar'));
Any help is appreciated :)
Actually, I think you need some state container. To share state(in your case AccountInfo) between all of your components.
Personally, I recommend using Redux. Because this container is completely predictable.
In result you code will looks like:
//create redux store somehow
ReactDOM.render(<AccountPanel store = {resuxStore}/>, document.getElementById('accountPanel'));
ReactDOM.render(<SideBar store = {resuxStore}/>, document.getElementById('sideBar'));

Does successful form elements are submited as parameters automatically on AJAX calls?

Do we have to include all form elements (ids and values) manually in the query string when making an Ajax call, or they are automatically (according to standard) included as parameters to the query string of the request?
Well, since no one is eager to answer my question. I will.
the quick answer is no. by standard let's say HTML standard. form element values are not automatically submitted a long with a request as parameters, when making an Ajax call.
but when you submit a form by submit() function of the form element, it will include all successful elements in the query and will send it as parameters to the server.
so If you are using Ajax, you have to include every elements which you need yourself.
however there are some utility functions that can help you. like the serialize() method in Jquery framework.
have fun :)

How to override Dojo's xhrGet and xhrPost?

We are extensively using Dojo's xhrGet and xhrPost in our application. This has been used across multiple JavaScript files. Now we need a uniform way in which we handle the exceptions that are returned from the server in case of an AJAX call. We don't want to handle this in all places where we are using Dojo's xhrGet or xhrPost. Is it possible to do that without disturbing any of the existing code? For example, when some exception is sent from the server as part of the ajax response, I need to display some message in a consistent way across the application.
Could you please suggest me a solution for this? Kindly let me know if any more information is required.
Use IO Pipeline Topics as I described in Generic Loading Icon in Dojo and you won't have to change your code at all.
did you look at the dojo/aspect or dojo/on ? You can define functions that get executed after a function was called (or before) with aspect.
Take a look at that:
http://dojotoolkit.org/reference-guide/1.8/dojo/aspect.html#dojo-aspect-after
Why dont you create a custom xhrArgs class using dojo/declare that has the same error function for all his children ?
http://dojotoolkit.org/reference-guide/1.8/dojo/_base/declare.html#dojo-base-declare
Lucian

Client side to server side calls

I want to change the list of available values in a dropdown depending on the value selected in another dropdown and depending on values of certain fields in the model. I want to use JQuery to do this. The only hard part is checking the values in the model. I have been informed that I can do this using Ajax. Does anyone have any idea how I will approach doing this?
AJAX is indeed the technology your looking for. It is used to sent an asynchronous request from the client browser to the server.
jQuery has an ajax function that you can use to start such a request. In your controller you can have a regular method tagged with the [HttpPostAttribute] to respond to your AJAX request.
Most of the time you will return a JSON result from your Controller to your view. Think of JSON as something similar to XML but easier to work with from a browser. The browser will receive the JSON and can then parse the results to do something like showing a message or replacing some HTML in the browser.
Here you can find a nice example of how to use it all together.

Resources