no callback function in cross domain json file - jsonp

i'm trying to use cross domain jsonp. i have done this before using the callback function in the json file from the other domain. i'm looking at an example json data file that google uses in one of its tutorials:
http://earthquake.usgs.gov/earthquakes/feed/geojsonp/2.5/week -- here obviously the callback function here is eqfeed_callback. in the json file i'm trying to use, there is no callback function that kicks everything off, there is just a bracket [. the file starts off like:
[{"Address":"4441 Van Nuys Blvd","City":"Sherman Oaks" ...
and ends like:
}]
what should i do? is there another way to get at the data without a callback function? i can't edit this file. it's a service that i have a subscription to.
thx.

If it's not your server, and the server doesn't support JSONP, there's no way you can force it to return jsonp. You could try adding ?callback=callback to your url to see if that convinces the server to wrap it in a callback, but if it doesn't, you're out of luck.
Well, almost. There is actually a really dirty hack that you shouldn't use, which is to override javascript's standard Array constructor to assign the contents of the array to a global variable. But that's pretty hideous and I strongly advise against it.
Better ask the maintainer of the service if they're willing to support JSONP. Or better yet, add a CORS header.

Related

Request URI too long on spartacus services

I've been trying to make use of service.getNavigation() method, but apparently the Request URI is too long which causes this error:
Request-URI Too Long
The requested URL's length exceeds the capacity limit for this server.
Is there a spartacus config that can resolve this issue?
Or is this supposed to be handled in the cloud (ccv2) config?
Not sure which service are you talking about specifically and what data are you passing there. For starters, please read this: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/414
Additionally it would benefit everyone if you could say something about the service you're using and the data you are trying to pass/get.
The navigation component is firing a request for all componentIds. If you have a navigation with a lot of (root?) elements, the maximum length of HTTP GET request might be too long for the given client or server.
The initial implementation of loading components was actually done by a POST request, but the impression was that we would not need to support requests with so many components. I guess we were wrong.
Luckily, the legacy POST based request is still in the code base, it's OccCmsComponentAdapter.findComponentsByIdsLegacy.
The easiest way for you to use this code, is to provide a CustomOccCmsComponentAdapter, that extends from OccCmsComponentAdapter. Then you can override the findComponentsByIds method and simply call the super.findComponentsByIdsLegacy and pass in a copy of the arguments.
A more cleaner way would be to override the CmsComponentConnector and directly delegate the load to the adapter.findComponentsByIdsLegacy. I would not start here, as it's more complicated. Do a POC with the first suggested approach.

Uploading files via SAP Gateway via SAPUI5 (function import vs create_stream method)

I was wondering what the best practice is regarding the uploading of files via the gateway.
There is a possibility to pass parameters via a function import. One could pass the name and binary content to a function import in the gateway and upload it that way.
Another possibility is to upload it via the CREATE_STREAM method found in the DPC_EXT class.
What is the cleanest way to do this? They both seem to be working just fine.
Create stream. It's the more HTTP, REST, and OData-compliant way.
Function imports are not compliant to these standards, and should be avoided.
Function import is a way to do operations that does not match CRUDQ operations. For example accepting a document or confirming sale, You could of course use a Create method or an update but if You alreday using them for something HTTP PUT and GET can be used for function import.
It however should NOT be used if the operation matches Create Read Update Delete or Query.
EDIT:
Create (Read) Stream is a great (and recommended) way of sending files and it also uses GET and PUT so use this if You're just sending files (even with parameters).
Cheers.

Call XmlHttpRequest from WebAssembly

I try to understand what the best and most efficient way is to call XmlHttpRequest from WebAssembly.
I found http://webassembly.org/getting-started/js-api/ which seems to explain how to make calls between JavaScript and WebAssembly.
In order for getting this to work it seems to me I have to do the following:
Write a JavaScript function that I import into WebAssembly which calls XmlHttpRequest
Write a WebAssembly function that I export from WebAssembly which JavaScript calls when the XmlHttpRequest is complete.
In case I want to have a dynamic number of concurrent XmlHttpRequests running, I would also need the imported function to provide a handler that is then provided back by JavaScript to the exported function.
I now have a number of questions:
Is the above accurate and the way to do it?
How do I transfer the URI from WebAssembly to XmlHttpRequest? Do I have to either import or export a WebAssembler.Memory object to/from WebAssembly and place the URI in that?
If the answer to 2 is yes, this WebAssembler.Memory object will be like a global-variable but this can work because there is only one thread. Correct?
Similar to 2, how do I transfer the result of the XmlHttpRequest back to WebAssembly? Also in an imported/exported WebAssembler.Memory object?
In connection with 4, how do I get the result of the XmlHttpRequest into WebAssembly in the most efficient way - e.g. with as few copies as possible? Do I need to copy the result of XmlHttpRequest into the WebAssembler.Memory object from the JavaScript code? And again, this WebAssembler.Memory object is a global variable? I guess I could let the call form WebAssembly to JavaScript pass an index to indicate where in WebAssember.Memory the result should be placed?
Yes, this is correct.
You can transfer URIs as strings, as explained in this question about strings
When WebAssembly supports threads, you'd call out to JavaScript and could just heap-allocate the string, pass out its pointer+length, and delete on return from that call.
Yes, transfer it back like a string.
Currently you have to do a copy, though the Community Group is discussing ways that would allow fewer copies to occur in the future. The notes for the latest such discussion are available from the WebAssembly meetings repository.

How is XHR a viable alternative to asynchronous module definition?

I'm learning about the case for asynchronous module definition (AMD) from here but am not quite clear about the below:
It is tempting to use XMLHttpRequest (XHR) to load the scripts. If XHR
is used, then we can massage the text above -- we can do a regexp to
find require() calls, make sure we load those scripts, then use eval()
or script elements that have their body text set to the text of the
script loaded via XHR.
XHR is using ajax or something to make a call to grab a resource from the database, correct? What does the eval() or script elements have to do with this? An example would be very helpful
That part of RequireJS' documentation is explaining why using XHR rather than doing what RequireJS does is problematic.
XHR is using ajax or something to make a call to grab a resource from the database, correct?
XHR is what allows you to make an Ajax call. jQuery's $.ajax for instance creates an XHR instance for you and uses it to perform the query. How the server responds depends on how the server is designed. Most of the servers I've developed won't use a database to answer a request made to a URL that corresponds to a JavaScript file. The file is just read from the file system and sent back to the client.
What does the eval() or script elements have to do with this?
Once the request is over, what you have is a string that contains JavaScript. You've fetched the code of your module but presumably you also want to execute it. eval is one way to do it but it has the disadvantages mentioned in the documentation. Another way to do it would be to create a script element whose body is the code you've fetched, and then insert this script in the DOM but this also has issues, as explained in the documentation you refer to.

How to download data from a website introducing some parameters in Objective C

I'm new in objective C and I'm having problems to find this.
My app is going to be: 1) user introduces a parameter, and 2) my app returns the data in a list.
I have to do this using a website, but i don't know how to know do the request, and then how to pick up and parse the info.
How can I start??
I think that you can handle the filter parameter in the server with a cgi or php, in the app, make the request and get the response.
1.- Get the parameter from the user like a NSString.
2.- Create a NSURL from the string (and the server adress string).
3.- The use the class method dataWithContentsOfURL from NSData to initialize a NSData object from the response url.
4.- NSData is really flexible, so you can do anything with it.
Note: dataWithContentsOfURL is synchronous, so if you want async, take a look at Grand Central Dispatch.
It doesn't seem clear to me what you are trying to do.
If you are trying to call a webservice with some parameters or just calling a website plus parameters in the end of it?
If webservice , just use the ASIHTTP Library located in here:
http://allseeing-i.com/ASIHTTPRequest/
If website, just append your parameter to the end of the string and call it.