I ask if there are any way to update an entity using javascript and symfony2.
when clicking on a button, a function in javascript should be called to update the entity in database
I use symfony 2.6
This is called Ajax. Javascript code sends a request (POST/GET/PUT) to an URL (Managed by Symfony), which can answer.
Communication between Javascript and Server is generally done using POST, and data sent back is generally done in XML/HTML or JSON.
There are plenty of tutorial and documentation, for example:
http://api.jquery.com/jquery.ajax/
You can also look at REST, that defines common API on the Server side. There is a module that helps defining this interface with Symfony:
http://symfony.com/doc/current/bundles/FOSRestBundle/index.html
Related
I have a web application with a client that receives data from a server. I have the data in NodeJS, but I want to pass the data to a Javascript file. The Javascript file is included in a HTML file, so I can't make the files communicate with eachother.
I am new to NodeJS, so it can be a stupid question, but anyones help is appreciated
This is for a project where I need have a data stream, and I need to pass it into a web application. I tried to pass the data to different page inside my application and then I tried to get that data on that page inside my web application via Javascript, but I couldn't make that work. I'm not even sure if its possible at this point.
Your node server can't communicate with your front-end without a specific way of communication like websocket, you have many other way to communicate with your front-end as node-server, take a look at server send event for example.
By the way your front-end can call your node server more easely with a get request as said #tomerpacific in comment.
For that you have to open a route with your express app. Routing with express
And for call it on a GET request, for that you can use the XMLHttpRequest, and if you have implemented jQuery on your front, you can use Ajax jQuery.
I'm quite new to web applications and have decided to create a single page web app hosted on Heroku.
My understanding of this web app is as follows:
Client side (AngularJs) has input text box, once button press it requests server side endpoint
Server (NodeJs) uses data from client to call external API (e.g imgur API) and returns json
Server processes json and responds to client with information
Client uses server response to render user interface
Main Concerns
Best practices for external API calling: Should I have an API wrapper class that allows me to call custom methods that return specific external api calls?
How should I handle http error responses?: I understand that NodeJs is async by nature and all http calls are done async as well. If there are multiple responses, error or success, how do I go about handling them all without doing a custom set of ".error()" and ."success()" methods for each call?
Furthermore
I cannot seem to find a good reference material for a simple NodeJs back end like the one I described. Please direct me if there are any.
I recommend looking at this Scotch.io article for creating a Single Page MEAN Application:
Setting Up a Single Page MEAN Application Starter Kit
I'm using MVC 3. I've created a csv file in an Action Method on the server (called GetCSV()). It's an [HttpPost] action method. What I'd like to do is send that csv file directly to the web browser as a downloadable file. I got this to work using window.open(), however, that is a GET method by nature and I need something that makes use of POST since I will need to pass a lot of parameters into it. Ideally, I would like to use Ajax since I can easily pass a whole lot of parameters back to the server using this approach. Any ideas in how I can use an Ajax call to pass the parameters to the server and then somehow have the response open as a downloadable file? I'd appreciate any advice!
My solution for this was to use Microsoft's MVC 3 Ajax Form instead of JQuery's Ajax. I found out by pure accident a number of months ago that if you don't specify a "success" function for an MVC Ajax form, it just sends the file to the web client for download. This is what I need to happen. I tried this and it did indeed work as intended.
You can't save a file to the local filesystem using javascript (at least in a standard way supported by all browsers), or ajax. That's why the recommended approach is to do it without ajax, and usually through a GET.
You can however convert a json object with parameters to a URL, through jquery's .param() as shown on this answer.
If indeed you want to explore the javascript alternative, maybe you can look into the FileSystem API supported only by chrome AFAIK.
I have a web site showing some data. It is constructed of:
- A web app, showing data.(ASP.Net app, but I don't use server side features in showing data; It's pure HTML and JavaScript)
- A Service providing data in Json format.(WCF)
the client requests data and receives and shows them.
Now I want to change the process in order to works in push base strategy.
I googled and I found out that that Comet is a good choice, but I don't found practical samples in my case.
Some samples had client with php (server-side) and so on.
Now I want some hints on using comet in a way that client is pure JavaScript and HTML and server is WCF (server pushes Json to JavaScript )
look at nComet it is an asp.net implementation of comet, not sure if it is wcf yet, but i would have thought much of the code would be reusable.
Or better pokein
As the title suggests, I'm trying to figure out how to call a soap service using JavaScript. The SOAP Service is being run on Tomcat on my local machine. Along with accessing the SOAP service, I can also download/access/read the WSDL very easily.
I've been hitting my head against the wall for days now with this problem. While researching, I'm come across short examples, but none are comprehensive and detail how to accomplish this from start to end. That, or I've found a solution but it only works for IE or Mozilla.
Any ideas how to call a SOAP web service using Javascript (on major browsers)? Thanks!
(PS: I'm also using jquery. So if you want to accomplish this using some slick jquery tool, please feel free to suggest it)
SOAP is just XML so it should be possible to do this, however I'm not aware of any existing SOAP Clients written in JS
A more common method would probably be:
JavaScript initiates an XHR object which calls to a server-side AJAX helper using either GET/POST parameters, or a JSON encoded object
AJAX helper makes the call to either a Database or Web Service, as appropriate, and outputs required data object(s) as either JSON or XML
JavaScript parses response body (JSON or XML) and takes required action using specified data.
This has a couple of advantages over trying to call WebServices directly from JavaScript:
SOAP XML can be quite complex, which means more data to transfer to and from the client, which may be a slow connection. JSON in particular, but also an XML schema that just has the required data would be a much more economical on data usage
If the WebService requires any kind of authentication the authentication details will be exposed to all visitors.
Web Services are generally used for to standardise communications between separate systems, rather than for communication between the front and back end components of the same Application/Site.