fetch error

Hi.
When I use fetch, It would have some error.

This is part of my code.

    function getData() {
            fetch(url, {
    		method: 'POST'
    	}).then(function(response) {
    		items.value = Backend.parsingXMLData(response._bodyInit);
    		resultText.value = response.statusText+". We got the data.";
    		if (items.value.totalCount != 0) {
    			Storage.write("search.xml", response._bodyInit)
    				.then(function(succeeded) {
            			        if(succeeded) {
    						console.log("Successfully wrote to file.");
        				} else {
	        				console.log("Couldn't write to file.");
		        		}
		        	});
        	}
    	}).catch(function(error) {
    		console.log(JSON.stringify(error));
    	});
    }

    function getSido() {
	if (address.data1.length == 0) {
		fetch(url, {
			method: 'POST'
		}).then(function(response) {
			code.value = Backend.parsingXMLData(response._bodyInit);
			code.value.items.forEach(function(item) {
				address.data1.add(item.item.ADDR1);
			})
			if (code.value.totalCount > 10) {
				url = url + '&pageNo=';
				for (var i = 2 ; (i-1)*10 <= code.value.totalCount ; i++) {
					fetch(url+i, {
						method: 'POST'
					}).then(function(response) {
						code.value = Backend.parsingXMLData(response._bodyInit);
						code.value.items.forEach(function(item) {
							address.data1.add(item.item.ADDR1);
						})
					});
				}
			}
		}).catch(function(error) {
			console.log(JSON.stringify(error));
		});
	}
    }

function getSgk() {
	if (address.data1.length == 0) {
		fetch(url, {
			method: 'POST'
		}).then(function(response) {
			code.value = Backend.parsingXMLData(response._bodyInit);
			code.value.items.forEach(function(item) {
				address.data2.add(item.item.ADDR2);
			})
			if (code.value.totalCount > 10) {
				url = url + '&pageNo=';
				for (var i = 2 ; (i-1)*10 <= code.value.totalCount ; i++) {
					fetch(url+i, {
						method: 'POST'
					}).then(function(response) {
						code.value = Backend.parsingXMLData(response._bodyInit);
						code.value.items.forEach(function(item) {
							address.data2.add(item.item.ADDR2);
						})
					});
				}
			}
		}).catch(function(error) {
			console.log(JSON.stringify(error));
		});
	}
    }

This code is well in Local Preview.

But, isn’t well in iOS Preview.

getSido is running well. But, getData and getSgk is not running.
And it send Same error message. “line:435, column:29, sourceUrl:js/fetch.js”

Fuse version: 0.26.0
OS X 10.11.6

Hi, thanks for the bug report. :slight_smile:

In general it can be hard for us to reproduce your problem with only a part of your code. If it is possible for you to provide a self-contained example demonstrating the problem that would be very helpful!

Thanks for your reply.

https://github.com/HandongKim/BugReport

This is the example.

It has functions getSido, getSgk, getEmd.

getSido run fine. But, getSgk send same error message.

Hi, thanks for the example.

I have been away on vacation for a while and forgot about this thread, so sorry for the late reply.

I cloned your BugReport repo and attempted to run it, but I’m not sure what I should be looking for here.
The first thing I noticed was that I got a JS error in fetchBug.ux:206, but that seem to be because the properties names are missing.

When I change these lines to:

		module.exports = {
			address: address,
			getData1: getData1,
			getData2: getData2,
			getData3: getData3,
			selectData1: selectData1,
			selectData2: selectData2,
			selectData3: selectData3
		};

I get rid of that error message.

After that when i push the fetchData buttons I seem to get some Korean text back, but unfortunately I don’t know if that is what is expected. Sadly I don’t know any Korean. :wink:

I also see you recently made a couple additional commits to the BugReport repo. Are these intended, or should I rather try the initial commit?

Thanks for your reply.

That is not what I intended.
I have translated commit to English.
Plz check again. :slight_smile:

Ok, I will have another look at it now.

I see here that it’s really 4 separate issues you got. I will take a quick look at all of them, but for future discussion it will be best if you open a separate forum post for the ones unrelated to this post.

That makes it a lot easier for us to track the issues and follow the discussion.

And thanks again, we really appreciate you putting an effort into creating an example which demonstrates these problems, it’s very helpful :slight_smile:

Regarding the fetch bug:

From what I can tell “fetchData” fetches the url. The second time I press it nothing happens, which would be expected as address.data1 has now been modified (so fetchBug.ux:126 is no longer true).

However, the “fetchData2” and “fetchData3” buttons don’t seem to do anything because data.sido is set to “시도” and data.sgk is set to “시군구”, due to the surrounding if blocks.

But from what I can tell this is all expected behavior for this code. Or is it something I’m missing here?

EDIT:

Ok, after going through the code a bit closer, I now understand I need to click on the downloaded data1 text. Then I get an error in fetch.js:435. Will look a bit more at exactly why.

Thank you for your quick reply.

Among the issues that I posted, Scrollview issue seems to be solved in new release. I will check that issue.

Then I will post a new forum related to the other issues.

It would be very helpful if you check the fetch issue. :slight_smile:

I just found out what the problem is. It looks like the HTTP backend used on iOS does not support UTF-8 characters in the URI. IIRC compliant URI’s should not contain unencoded UTF-8 characters, so encodeURIComponent must be used, which is a good thing to do in any case when building an URI.

Specifically if you replace the line fetchBug.ux:144 with:

var url = 'http://openapi.onbid.co.kr/openapi/services/OnbidCodeInfoInquireSvc/getOnbidAddr2Info?ServiceKey=LEVQhgclvGUKoC%2BJrvokKajzK6OsTFRinprds4qBzZj1PJMDZUQ8SRTm0lmzbj1jzC9IaZLqEm1G%2FhAdHV5R5A%3D%3D&numOfRows=999&ADDR1='+encodeURIComponent(address.sido.value);

it should work ok.

And then the other issues will be followed up in new threads, thanks for that. :slight_smile:

Thanks for your help.

It did help me a lot. :slight_smile: