Call Server Side function/event using jquery - jquery-ui

How to call a server side function/event using jquery ?

What you are looking for is the AJAX jQuery methods. You can use these to either send a GET or POST request to the server, and the server can process whatever needs to be done server-side and return the results to jQuery. I suggest looking through the jQuery API page I linked to get a better understanding of how AJAX works within jQuery.

To call a server side functionality. You need to understand the concept of Ajax. jquery also provides some of the methods which can be used to make ajax hits.

Related

ASP.NET MVC server-side file upload progress calculator

I am trying to implement basic progress bar for file uploads to work across multiple browsers without additional plugins like Flash or Silverlight. There are multiple ways to approach this problem on a client-side, however I can't find anything to work on a server.
Anywhere on MVC controller (before/on authorization and before/on executing action) file is already uploaded to server as HttpPostedFileBase. If I use basic HTTP handler for form submission, I have access to Context.Request.InputStream as well as to Context.Request.Files, but as soon I access the properties the stream/files would load silently.
I did extensive research, but could not find anything what allows me to Cache or store file upload process in Session. That would at least allowed me to use periodic AJAX requests from a client to monitor the progress.
What am I missing?
You should try a Javascript alternative, instead of handling it server side. The controller should only come in action when the request is done sending.
Try this JavaScript/jQuery alternative to Flash/SL
http://blueimp.github.io/jQuery-File-Upload/

avoiding iframes, but having some iframe like activity in Rails

I have two sites, my main site and a help site with documentation. The main site is rails but the other is simple a wordpress like blog. Currently I have it being pulled into the main site with an iframe, but is there a good way to pull in the html from the other site as some sort of cross-domain (sub-domain actually) partial? Or should I just stick with what works?
If the data sources were all on the same domain, you would be able to utilize straight AJAX to fetch your supplemental content and graft it onto your page. But, since the data is from different domains, the same origin security policy built into web browsers will prevent that from working.
A popular work around is called JSONP, which will let you fetch the data from any cooperating server. Your implementation might look something like this (using jQuery):
$.getJSON(
"http://my.website.com/pageX?callback=?",
function(data) {
$("#help").append(data)
}
)
The only hitch is that the data returned by your server must be wrapped as a javascript function call. For example, if your data was:
<h1>Topic Foo</h1>
Then your server must respond to the JSONP request like this:
callbackFunction("<h1>Topic Foo</h1>")

How does Facebook pull website data when it sees you've typed a URL into a wall post?

So I'm writing a post on my wall and type a URL into the main body of the post. As soon as I finish the URL, Facebook creates a little section underneath which has the title, description, and an image from the url I typed.
Without getting too indepth, how is this done and what is the best way of make something similar myself?
jQuery (or some other framework that lets you do Ajax easily) to communicate between browser client and webserver
PHP/ASP.NET/Python (or some other scripting framework on the backend) to fetch the url
Facebook also has a meta data specification you might be interested in, to let developers further define what gets shown in a Facebook page.
I believe Facebook is written in PHP. And PHP does this easily.
FOpen can be used to access files on other sites. There are other functions but this will get you started. Then it's a matter of parsing the html you get from the url to get what you want.
http://php.net/manual/en/function.fopen.php
You have a couple choices. You can fetch it using Ajax from the client; or you can fetch it from your server.
If doing it from your server in asp.net then you need to use HttpWebRequest.
FB does an asynchronous JavaScript call to fetch that data without reloading the window you're on. Lookup ajax and libraries like jquery do this: http://api.jquery.com/category/ajax/

MVC show notification to user when event happens on server

i've got a situtation where we have a web site (mvc project), and a wcf service, when service gets message i need to show a notification to user who's on the web site with this message contents.
would be glad if you can show me the place where to start!
Thank You !
You probably need some javascript on your page that polls the server at a certain interval to check if there is something to show to the user.
Here is a nice article on how to create a WCF service and call it from the browser using JQuery
I think you need to place javascript timer on your page which will do ajax for example: "/Messages/GetLastUnreadMessage".
You'll need to have a bit of javascript that makes an AJAX call back to your site from the client page on a regular basis that checks to see if there are new messages, and displays them if there are.
There's no way for your web server to 'notify' an already rendered client page in the other direction (providing I understand your requirement correctly).

ASP.NET MVC Ajax helpers block other Ajax requests

I have this very strange problem.
Currently I'm using ASP.NET MVC Ajax Ajax.BeginForm helper.
After it creates successful post request to server and receives response my other components that use ajax, are not able to request anything from server (Firebug just does not display any requests, at the same in another browser window I can get response from server just fine the problem is defiantly not on server side).
But when I return nothing in response to Ajax.BeginForm helper request my other ajax components are able to make requests to server.
Is it a know issue with ASP.NET Ajax or I'm doing something wrong?
Thank You very much!
Your probably crashing the application server with that request. Check your server logs. If your debugging this kind of thing happens, your maybe not catching an exception.

Resources