Hi all,
I’m having some trouble getting fetch to work. When I call fetch, I get a System.NotSupportedException. I’ve done some research and it’s possible I might be doing something wrong, because I’ve used fetch before in my fuse apps.
My Fuse version is 0.12.2 build 6298 running on Mac OS X El Capitan
My code is below.
<App Theme="Basic">
<JavaScript>
'use strict'
function ResultsData(data) {
this.kit_code = data.kits.kit_code
this.location = data.kits.registered_at
let regDate = data.kits.registered_on.date.split(" ")
this.registration_date = ${regDate[0]} at ${regDate[1]}
}
/ MOCK /
let MOCK_RESULT = {
"kits":{
"kit_code":"SEL65179",
"registered_at":"United Kingdom",
"registered_on":{"date":"2011-07-20 15:23:54","timezone_type":3,"timezone":"UTC"}
},
"items":24
}
/ MOCK /
var Observable = require("FuseJS/Observable")
let API_ENDPOINT = "http://www.fusetools.com"
let URLS = {
search: ${API_ENDPOINT}/search
}
let showResults = Observable(false)
let isLoading = Observable(false)
let searchTerm = Observable("resource")
let results = Observable({})
let showOverlay = Observable(false)
let closeOverlay = () => {
showOverlay.value = false
showResults.value = false
isLoading.value = false
}
let fetchResults = () => {
showOverlay.value = true
isLoading.value = true
/ MOCK REQUESTS /
// setTimeout(function () {
// if (!!showOverlay.value) {
// isLoading.value = false
// results.value = new ResultsData(MOCK_RESULT)
// showResults.value = true
// }
// }, 2000)
/ END MOCK /
console.log(URLS.search + "?q=" +searchTerm.value)
fetch(URLS.search + "?q=" + searchTerm.value)
.then((response) => {
return response.json()
})
.then((jsonResponse) => {
console.log('response: '+ JSON.stringify(jsonResponse))
isLoading.value = false
results = jsonResponse
}).catch((e) => {
console.dir(e)
// isLoading.value = false
})
}
module.exports = {
fetchResults,
isLoading,
showResults,
searchTerm,
showOverlay,
results,
closeOverlay,
}
</JavaScript>
<DockPanel>
<Text ux:Class="KitPropertyLabel" FontSize="14" TextColor="#999" />
<Text ux:Class="KitPropertyDetail" FontSize="13" TextColor="#555" />
<Circle Height="20" Width="20" Color="#fff" ux:Class="CloseButton" Alignment="TopRight" Clicked="{closeOverlay}">
<Text Alignment="Center" FontSize="15" Value="×" />
</Circle>
<Text ux:Class="ResultStatus" TextAlignment="Center" Padding="0,10" TextColor="#11dd11" FontSize="20" />
<Android.StatusBarConfig IsVisible="false" IsNavigationBarVisible="true" Color="#f89829" />
<BottomBarBackground Dock="Bottom"/>
<CloseButton Offset="-15, 35" Layer="Overlay" Opacity="0" ux:Name="closeOverlayButton"/>
<StackPanel Alignment="Center" Height="0" Width="0" Layer="Overlay" Color="#00000066" ux:Name="overlay">
<LayoutAnimation>
<Resize X="1" Y="1" RelativeTo="LayoutChange" Duration="0.2" Easing="CubicInOut"/>
<Move X="1" Y="1" RelativeTo="LayoutChange" Duration="0.2" Easing="CubicInOut"/>
</LayoutAnimation>
<WhileTrue Value="{isLoading}">
<Rectangle Fill="#fff" Alignment="Center" Height="80" Width="120" CornerRadius="5">
<EnteringAnimation>
<Move Y="1" RelativeTo="ParentSize" Duration="0.2"/>
</EnteringAnimation>
<Text Alignment="BottomCenter" Padding="0,5" FontSize="12" TextColor="#f89829" Value="Searching..."/>
<DropShadow Color="#0002" Angle="90" Size="10" Spread="0.1" Distance="4"/>
</Rectangle>
</WhileTrue>
<WhileTrue Value="{showResults}">
<StackPanel Padding="10" Color="#fff" Width="85%" >
<EnteringAnimation>
<Move Y="1" RelativeTo="ParentSize" Duration="0.2"/>
</EnteringAnimation>
<DropShadow Color="#0002" Angle="90" Size="10" Spread="0.1" Distance="4"/>
<Panel>
<ResultStatus Value="Kit found"/>
</Panel>
<Grid Padding="5" ColumnCount="2" Columns="2, 3">
<KitPropertyLabel Value="Kit" />
<KitPropertyDetail Value="{results.kit_code}"/>
</Grid>
<Rectangle Height="2px" Color="#ddd"/>
<Grid Padding="5" ColumnCount="2" Columns="2, 3">
<KitPropertyLabel Value="Registered in" />
<KitPropertyDetail Value="{results.location}" />
</Grid>
<Rectangle Height="2px" Color="#ddd"/>
<Grid Padding="5" ColumnCount="2" Columns="2, 3">
<KitPropertyLabel Value="Registration Date" />
<KitPropertyDetail Value="{results.registration_date}" />
</Grid>
</StackPanel>
</WhileTrue>
</StackPanel>
<Panel Dock="Fill">
<!-- <Panel Alignment="Center" Height="0" Width="0" ux:Name="overlayHidden">
</Panel>
<Panel Alignment="Center" Height="100%" Width="100%" HitTestMode="None" ux:Name="overlayVisible"> -->
<!-- </Panel> -->
<!-- <FileImageSource ux:Key="logo" File="./pictures/logo.png" /> -->
<WhileTrue Value="{showOverlay}">
<Set overlay.Height="100%" />
<Set overlay.Width="100%" />
<Change closeOverlayButton.Opacity="1" Duration="0.5" />
</WhileTrue>
<WhileFalse Value="{showOverlay}">
<Set overlay.Width="0%" />
<Set overlay.Height="0%" />
<Change closeOverlayButton.Opacity="0" Duration="0"/>
</WhileFalse>
<Page ux:Class="SlidePage">
<EnteringAnimation>
<Move X="1" RelativeTo="ParentSize" />
</EnteringAnimation>
<ExitingAnimation>
<Move X="-1" RelativeTo="ParentSize" />
</ExitingAnimation>
</Page>
<SlidePage ux:Name="searchPage">
<StackPanel Alignment="Center">
<Image Margin="0,0,0,50" Width="250" File="pictures/logo.png" />
<TextInput Value="{searchTerm}" PlaceholderText="Enter Kit Code" PlaceholderColor="#898989" />
<Rectangle Width="200" Padding="10" Background="#f89829">
<WhilePressed>
<Move Y="1" />
</WhilePressed>
<Text Alignment="Center" Value="Search" FontSize="18" TextColor="#fff"/>
<Clicked>
<Callback Handler="{fetchResults}"/>
<!-- <NavigateTo Target="resultsPage" /> -->
</Clicked>
</Rectangle>
</StackPanel>
</SlidePage>
<SlidePage ux:Name="resultsPage" ux:AutoBind="false">
<StackPanel>
<Text>Welcome to page 1!</Text>
<Button Text="Go Back">
<Clicked>
<GoBack />
</Clicked>
</Button>
</StackPanel>
</SlidePage>
</Panel>
</DockPanel>
</App>
The error I get is below
LOG: System.NotSupportedException: http://www.fusetools.com/search?q=resource
at System.Net.WebRequest.GetCreator (System.String prefix) [0x00000] in <filename unknown>:0
at System.Net.WebRequest.Create (System.Uri requestUri) [0x00000] in <filename unknown>:0
at System.Net.WebRequest.Create (System.String requestUriString) [0x00000] in <filename unknown>:0
at MyHttpLib.HttpRequest..ctor (System.String url) [0x00000] in <filename unknown>:0
at Uno.Net.Http.Implementation.CilHttpRequest..ctor (IHttpMessageHandlerRequestCallbacks requestCallbacks, System.String method, System.String url) [0x00000] in <filename unknown>:0
at Uno.Net.Http.Implementation.CilHttpRequest.Create (IHttpMessageHandlerRequestCallbacks requestCallbacks, System.String method, System.String url) [0x00000] in <filename unknown>:0
at Uno.Net.Http.HttpMessageHandlerRequest..ctor (Uno.Net.Http.HttpMessageHandler handler, System.String method, System.String url, IDispatcher dispatcher) [0x00000] in <filename unknown>:0
at Uno.Net.Http.HttpMessageHandler.CreateRequest (System.String method, System.String url, IDispatcher dispatcher) [0x00000] in <filename unknown>:0
at Fuse.Reactive.FuseJS.Http+FuseJSHttpClient.CreateRequest (System.Object[] args) [0x00000] in <filename unknown>:0
at Fuse.Scripting.V8.Marshaller+CallbackWrapper.Call (Fuse.Scripting.V8.Simple.UniqueValueVector args) [0x00000] in <filename unknown>:0
I’m sure I’m doing something wrong, but can’t see it (yet). I can provide more information if need be.
Kind regards,
Victor