I am trying to make a Firefox extension which will use a webservice. I was looking online to find a way to do this. I was wondering if someone could explain what the following objects/methods do:
service.useService(___, ___);
service.<Service Name>.callService();
If there is an alternative that does not include these objects, I would be happy to hear about it.
Thank you very much
It appears you are using IE specific code to call the webservice, and according to this response it may not be supported in newer browsers now:
http://www.eggheadcafe.com/software/aspnet/31984555/you-can-use-xmlhttpreques.aspx
For more on the service.useservice function you may find this page helpful:
http://www.15seconds.com/Issue/040708.htm
If you have control over the web service then you can get it to either reply with a JSON or use a REST web service, as well as a SOAP web service, as javascript can work well with REST, or with a form-based (POST/GET) web service, as opposed to SOAP.
Related
Working on a simple HTML application that makes calls to an API using jQuery. Would like to avoid someone getting the API address (via looking at the source and/or network traffic) and making calls directly to the API without the HTML pages getting loaded first. Thinking about adding a header or cookie that the API can validate to ensure this request is coming from the Javascript embedded in that page, and not someone calling the API direct. However, even this could be replicated by someone looking to talk to the API directly. Would like to keep this a simple HTML project as much as possible (realize creating a Node.js version of the application, or using Thymeleaf in Spring Boot would give more options to obscure the API). It feels like this is a limitation of doing an HTML/Javscript solution. But, maybe we are missing something obvious. Any tips?
How can I connect to mysql DB from JS function?
I found this question:
How to connect to SQL server database from javascript?
but it doesn't work on Chrome, because they're using ActiveXObject.
Thank you.
There is no good solution on web browser side which will allow you to work with all browsers. There are many disadvantages to work with database on browser site.
First of all, you show your database structure and it is very dangerous. Imagine, how easier is to make SQL-injection while you know tables and fields?
You have to establish connection in some way using password which will be shown to third party users. Or you have to set password-less connection, which is also dangerous.
When you establish connection with database, somebody can easly execute own query what is trivial, because you are showing your structure.
I strongly recommended you to not do it on browser side.
but I have cross-domain problem, so I just need to do simple select from db
Direct browser-to-database communication is definitely not a proper solution.
If you want to get a list of values out of the db, just write a method in whatever server-side language you prefer (or need) to use, make the client-side JavaScript code call that method through its public URI and parse the response body into some data structure.
A more general solution to this kind of problems is XMLRPC (for the record, I've used it under Code Igniter / Flash ActionScript 3.0), though it's not all that simple to use.
If you need to get data from two different domains, then implement the above on both of them and make the JavaScript code call the two different URIs and combine the data (if needed).
You must use AJAX, because JavaScript itself can't connect to server. You can call some PHP script with AJAX and in JavaScript handle response from it. See jQuery.ajax().
make Ajax call from your javascript to php which connects you to database
Without some sort of plugin, or sending requests to a server side application that will access the database for you, you can't. So focus on those instead, specially server side apps.
A comment under this question
How to make a database connection
suggests that's only possible with a particular mix of Microsoft technologies specifically designed to deploy desktop-like software using a web browser. The bits mentioned there are:
HTA - HTML Applications
JScript - a Microsoft flavor of JavaScript
ActiveX objects
A link is also provided: Introduction to HTML Applications (HTAs)
please tell me how to consume webservice (.net) using javascript.
its SOAP.
Thanks
You use AJAX.
In particular the XMLHttpRequest object.
Look at the jQuery ajax API - it makes AJAX easier to use.
I don't think there is a Javascript library that consumes SOAP out of the box. Dojo offers a lot of functionality in that direction, RPC-calls for example, and is probably the one that comes closest.
IBM did some work there that you might want to check out.
This (including Dojo) is a lot of non-trivial stuff to learn but SOAP is a nasty beast, if you really need to interface to a SOAP service with JS you will have to invest some time.
See:
http://www.ibm.com/developerworks/web/library/wa-dojowebresponse/index.html?ca=drs-
SOAP Requests in Dojo
Both .asmx and .svc (wcf) expose javascript enabled bindings - this is easy to find on the internet.
Example:
http://dotnetbyexample.blogspot.com/2008/02/calling-wcf-service-from-javascript.html
Normally you just append /js to the url of the endpoint and javascript providing a proxy is returned.
This proxy code relies on the ASP.NET AJAX framework, but you can easily use it with any other ajax-enabling framework by using this shim.
I've been looking around for a decent jQuery feed/XML parser and found good plugins like jFeed and jParse (among a few others). None of these support retrieving an external feed though, which is something I'm after.
Pretty sure this is down to jQuery's $.ajax() method rather than the plugins themselves (as they'll be built from this).
Is there some sort of hack I could use to override jQuery, or a raw JavaScript alternative? Better still would be a better plugin, but even the more popular ones I found didn't support it.
Thanks
try this tuturial:
http://visualrinse.com/2008/09/24/how-to-build-a-simple-rss-reader-with-jquery/ (archive.org)
and demo
http://visualrinse.com/bradley/mm491/reader.html (archive.org)
I recently built AMJR (Asynchronous Multifeed JS Reader) cause I couldn't find something similar to what you ask...
AMJR was written to cover a specific need: A multi-feed reader written in JS. In other words, a feed reader that takes multiple feeds as input and outputs the last X from all the feeds in chronological order. An implementation you'll surely find in server-side languages but not in JS! Having such a functionality reside on the user's browser (client-side) can lift off some processing load especially on high-traffic sites which happen to integrate external feeds. Think of AMJR as your own "Yahoo Pipes" widget to mashup feeds altogether in the same output block.
To summarize things for AMJR:
It can fetch multiple feeds at once while sorting them at the same time chronologically.
It's simple to implement, small in size and fast to load.
It's non-blocking (asynchronous). This means that the browser will continue to load the rest of the page while feeds are loading.
It can handle a sh** load of feeds, but the resulting performance depends on your user's internet connection download speed. In this example I've deliberately chosen to fetch a ridiculous number of external feeds (150+) so you can see a) the non-blocking process and b) how fast it is.
Feeds are "proxied" via Google's infrastructure (or optionally via Yahoo's YQL), where they get "normalized" and then converted to (compressed) JSON before being sent back to the user's browser.
Built on jQuery but the dependency is so small you can easily adapt it to work with Mootools, YUI etc.
It works on all modern browsers.
Info/download at: http://nuevvo.com/labs/amjr/
Enjoy!
The answer looks to be on this page, using YQL instead of my own PHP proxy to handle the requests.
http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/
After finding out that it's not possible to do a simple JavaScript call to handle these requests, this jQuery plugin looks ideal, going to try it out later.
In fact, for parsing of RSS feeds without jQuery you can use the Google AJAX Feed API. Works a treat.
http://code.google.com/apis/ajaxfeeds/examples.html
Thanks for the replies
If by retrieving an external feed you mean getting a feed from a different domain that the one your web application is, you can't (Same origin policy).
You will need some kind of proxy on the server side, like a PHP or python script (or whatever your favorite language is) that queries the external feeds and returns their contents to your application.
The jFeed plugin you checked has an example of a PHP proxy.
jFeed has a php proxy. I just had this need and jFeed was able to retrieve an external. PLease edit your comment if NOT using php is a requirement.
ANSWER (From what we know): Use jFeed!
:: However I just found out if your feed is 'not well-formed' it will break jFeed. :: Be warned
I can only recommend jFeed. I use a fork of it ( https://github.com/uhlenbrock/jfeed ) together with my phonegap project. The fork adds support for parsing the creator tag, and it works perfectly out of the box.
I'd like to access some Google API's from within an iPhone native app. I'm not a web programmer and have never used AJAX, but I'm guessing I need some kind of bridge between Objective-C and Javascript. Ideally I'd just fire XML at Google and process the result.
I really have no idea were to start.
Has anyone successfully done this, or know of any good resources?
See gdata-objectivec-client : the official Objective-C client library for Google Data API's (it works on the iPhone too.) See http://code.google.com/p/gdata-objectivec-client/.
Unless you mean the AJAX Search API - see http://code.google.com/apis/ajaxsearch/documentation/#fonje - that will provide a JSON response.