$.getJSON Not working in deployment server - asp.net-mvc

I used this post Globalize error with local numbers on .Net MVC Project to install the new version of Globalize in Asp Mvc Application.
So In the _Layout.cshtml I added this code
<script>
(function () {
$(function () {
$.when(
$.getJSON("/Scripts/cldr/supplemental/likelySubtags.json"),
$.getJSON("/Scripts/cldr/main/fr/numbers.json"),
$.getJSON("/Scripts/cldr/supplemental/numberingSystems.json"),
$.getJSON("/Scripts/cldr/main/fr/ca-gregorian.json"),
$.getJSON("/Scripts/cldr/main/fr/timeZoneNames.json"),
$.getJSON("/Scripts/cldr/supplemental/timeData.json"),
$.getJSON("/Scripts/cldr/supplemental/weekData.json")
).then(function () {
// Normalize $.get results, we only need the JSON, not the request statuses.
return [].slice.apply(arguments, [0]).map(function (result) {
return result[0];
});
}).then(Globalize.load).then(function () {
var culture = "fr";
Globalize.locale(culture);
});
});
})();
</script>
But when i deploy in the server it doesn't work.
Ps: I added this in my web.config
<system.webServer>
...
<staticContent>
<remove fileExtension=".json"/>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
Please Help.

Try this way:
$.getJSON(#Url.Content("~/Scripts/cldr/supplemental/likelySubtags.json")),
$.getJSON(#Url.Content("~/Scripts/cldr/main/fr/numbers.json")),...
Might need to wrap it around in double quotes, just play around a little with the #Url.Content but I believe it will solve your problem
$.getJSON("#Url.Content("~/Scripts/cldr/supplemental/likelySubtags.json")"),
$.getJSON("#Url.Content("~/Scripts/cldr/main/fr/numbers.json")"),...

Related

IOS 13 XMLHttpRequest Blob audio/mpeg returns as text/html

The code I have used to work on both Android and IOS, until I had to make the IOS version on ionic use WKWebViewOnly.
This is the code that was working on IOS (still works on Android):
var type = window.PERSISTENT;
var size = 50*1024*1024; // 50MB
window.requestFileSystem(type, size, successCallback, errorCallback);
function successCallback(fs) {
window.resolveLocalFileSystemURL(app.folder, function(dirEntry) {
dirEntry.getFile(mix_name, {create: true}, function(fileEntry) {
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = function(e) {
alert('Write success');
};
fileWriter.onerror = function(e) {
alert('Write failed: ' + e.toString());
};
var oReq = new XMLHttpRequest();
// Make sure you add the domain name to the Content-Security-Policy <meta> element.
oReq.open("GET", "https://domain-to-get-file.com/path/to/file.mp3", true);
// Define how you want the XHR data to come back
oReq.responseType = "blob";
oReq.onload = function (oEvent) {
var blob = oReq.response; // Note: not oReq.responseText
blob = blobToFile(blob, fileName);
fileWriter.write(blob);
};
oReq.send(null);
}, errorCallback);
}, errorCallback);
}, errorCallback);
}
function errorCallback(error) {
alert("ERROR: " + error.code)
}
function blobToFile(theBlob, fileName) {
// A Blob() is almost a File() - it's just missing the two properties below which we will add
theBlob.lastModifiedDate = new Date();
theBlob.name = fileName;
return theBlob;
}
In my index.html I have the meta tag:
<meta http-equiv="Content-Security-Policy" content="
default-src * data: cdvfile: gap: blob:;
script-src 'self' 'unsafe-inline' *.domain-to-get-file.com;
style-src 'self' 'unsafe-inline';">
And the plugins I have used are:
<plugin name="cordova-plugin-wkwebview-engine" source="npm" />
<plugin name="cordova-plugin-wkwebview-file-xhr" spec="~2.1.4" />
Works fine on Android but not on IOS 13.
I think i'm missing a security thing, but I have no idea how to fix that.
Thanks :)
This was a miss leading issue, but for anyone stumbling upon it.
The fix was to switch from using XMLHttpRequest to Fetch: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
I had no clue about Fetch until I saw this video: https://www.youtube.com/watch?v=tc8DU14qX6I&list=PLRqwX-V7Uu6YxDKpFzf_2D84p0cyk4T7X
and you will also need this: https://www.youtube.com/watch?v=zswi0cPMxsU to solve the CORS issue
I also did removed the plugins:
<plugin name="cordova-plugin-wkwebview-engine" source="npm" />
<plugin name="cordova-plugin-wkwebview-file-xhr" spec="~2.1.4" />
and adding this all-in-one plugin seemed to fix the issue.
https://www.npmjs.com/package/cordova-plugin-wkwebview-ionic-xhr
Added these two preferences in the ios platform in config.xml
<preference name="allowFileAccessFromFileURLs" value="true" />
<preference name="allowUniversalAccessFromFileURLs" value="true" />

jquery triggering not working in firefox extension

Steps to reproduce:
i created a hai.html and using pagemod i injected scripts into that, here is the code and that hai.html https://github.com/suneeshtr/trigger-test.git
Actual results:
injection of scripts and everything works fine except triggering. when i tried to append a file it works..
here is a part of code:
alert("content");
$(document).ready(function() {
var values = [{val:'santiagotactivos', meta:'Santiago Montero'},
{val:'johnnyhalife', meta:'Johnny Halife'},
{val:'arielflesler', meta:'Ariel Flesler'},
{val:'rbajales', meta:'Raul Bajales'}];
var customItemTemplate = "<div><span /> <small /></div>";
function elementFactory(element, e) {
var template = $(customItemTemplate).find('span')
.text('#' + e.val).end()
.find('small')
.text("(" + e.meta + ")").end();
element.append(template);
};
alert(JSON.stringify($("textarea")));
// here is how we use it
$('textarea').sew({values: values, elementFactory: elementFactory});
});
your question is not clear you can try this example
var src = [{val:'santiagotactivos', meta:'Santiago Montero'},
{val:'johnnyhalife', meta:'Johnny Halife'},
{val:'arielflesler', meta:'Ariel Flesler'},
{val:'rbajales', meta:'Raul Bajales'}];
$("#auto").autocomplete({
source:src
});
try this one too:
http://www.hawkee.com/snippet/9391/
$('#inputbox').triggeredAutocomplete({
hidden: '#hidden_inputbox',
source: "/search.php",
trigger: "#"
});

XPathException in invokeTransform running Saxon-CE example

I am trying to run the Saxon CE example on the IBM Developerworks
It raises this error:
SaxonCE.XSLT20Processor 23:04:41.615
SEVERE: XPathException in invokeTransform: Either a source document or an initial template must be specified
http://localhost:8984/static/SaxonceDebug/7FFD07C49946B3F4B1DE49E72F7E85FA.cache.html
Line 876
I can run other Saxon CE examples. Is this some API change?
As the error suggest you need to supply a source document or an initial template.
Something like:
<script>
var onSaxonLoad = function() {
Saxon.run( {
stylesheet: "books.xsl",
source: "books.xml"
});
or
<script type="text/javascript"> var onSaxonLoad = function() { proc = Saxon.run( {
stylesheet: 'scripts/stylesheet.xsl', initialTemplate: 'main' } ); };
</script>
Take a look at:
http://www.saxonica.com/ce/user-doc/1.1/index.html#!starting/running

Backbone and jquerymobile navigation issues - hash in URLs

I am using backbone.js and WebMatrix. I have problems with hash(#) in url though. To be more precise, I have on my router file this code:
routes: {
"" : 'myBooks',
"books/:id" : 'bookDetails'
}
and then i initialize the router
var initialization = function () {
Backbone.history.start();
};
So when I click this URL: "localhost:9548/#books/1" on my browser, the following message appears on my console (firebug) "NetworkError: 404 Not Found - //localhost:9548/books/1".
I have found already posts trying to solve a similar problem but I am not at all familiar with IIS Express (server configuration in general). So some posts for example also refer to web.config of my web application but I do not have any.
So for instance if I would create a web.config file with the following code
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rewriteMaps>
<rewriteMap name="StaticRewrites">
<add key="index.html#books/*" value="index.html" />
</rewriteMap>
</rewriteMaps>
</rewrite>
</system.webServer>
</configuration>
would solve my problem?
I apologize that I did not mention the fact that for the ui (and only) of my web app, I am using jquerymobile. Consequently, I have disabled the ajax navigation of jquerymobile:
$.mobile.ajaxEnabled = false;
$.mobile.linkBindingEnabled = false;
$.mobile.hashListeningEnabled = false;
$.mobile.pushStateEnabled = false;
$.mobile.changePage.defaults.changeHash = false;
Besides the change of a page is handled by this code:
var utility = {};
utility.changePage = function( viewID, effect, direction, updateHash ) {
viewID.attr('data-role', 'page');
$.mobile.changePage( viewID,{changeHash: updateHash});
};
Finally the function which handles my route is the following:
bookDetail: function (id) {
var myBook = myCollection.get(id);
var bookDetails = new BookDetails({ model: myBook });
$('body').append($(bookDetails.render().el));
$.mobile.changePage(bookDetails.$el, {changeHash: false });
}
Important: There is a chance that the problem is occurred because of the last version of the jquerymobile (1.3.0). Precisely, disabling hashListeningEnabled does not work properly as I have read.
Another feature is that I encounter this problem with Mozilla and Chrome but not with Internet explorer (using the last version of them).

Phonegap and jquery mobile : a href -> Origin null is not allowed by Access-Control-Allow-Origin

Im trying to use jquery mobile with phonegap, in a multi-page document.
Tring to use basic href links within the document, gives the Origin null is not allowed by Access-Control-Allow-Origin error which is quite annoying.
This is because the index page is refered to via file:// rather than http:// which webkit interprets as origin null. Has anyone got jquery mobile and phonegap to work in a multi page environment? if so how can you do it? If you add rel=external to the href tags the links work, but of course all the transitions are lost.
Cant find any info on this specific problem on stack overflow or teh internetz.
<!DOCTYPE HTML>
<html>
<head>
<title>PhoneGap</title>
<script type="text/javascript" charset="utf-8" src="phonegap-1.2.0.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script>
$(document).bind( "mobileinit", function(){
//alert("mobileinit fired");
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
});
</script>
<script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
<script type="text/javascript">
function onDeviceReady() {
navigator.network.isReachable("google.com", reachableCallback, {});
}
// Check network status
function reachableCallback(reachability) {
// There is no consistency on the format of reachability
var networkState = reachability.code || reachability;
var states = {};
states[NetworkStatus.NOT_REACHABLE] = 'No network connection';
states[NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK] = 'Carrier data connection';
states[NetworkStatus.REACHABLE_VIA_WIFI_NETWORK] = 'WiFi connection';
if (networkState != 0) online = true;
}
var online = navigator.onLine || false;
$(document).ready(function() {
$(document).bind('deviceready', function(){
onDeviceReady()
})
// Your main code
})
//Now if you about to make an AJAX call to load up some dynamic data, you can easily check to see if you're online
if(online) {
} else {
}
</script>
</head>
<body>
<h1>Welcome to PhoneGap</h1>
Edit html
</body>
</html>
Here's the official documentation on how to do just what you are looking for...
Hope this helps!
Leon's comment is the correct answer - you need to add rel="external" to static links.
To Test
Download mongoose http server
copy mongoose_xxxxxxx.exe file to your assets/www
Now you can design your html pages for jquery mobile without Access-Control-Allow-Origin
I think you can find the solution here: http://view.jquerymobile.com/master/demos/faq/how-configure-phonegap-cordova.php
$.mobile.allowCrossDomainPages = true;
$.support.cors = true;
$.mobile.phonegapNavigationEnabled = true
Although I have not gotten it to work, I think that here are the solution.
if you are targeting app above JELLY_BEAN(API Level 16), here is what you can add to MainActivity class.
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
super.appView.getSettings().setAllowUniversalAccessFromFileURLs(true);
}
Which will allow null origin XHR requests.

Resources