Why isn't this moving beyond the sqlstr


#1

Why doesn’t this code progress beyond the console.log(sqlstr) line?

exports.onConfirmTap = function (args) {
	var username = args.object.page.getViewById("username");
	var password = args.object.page.getViewById("password");
	var company = args.object.page.getViewById("company");
	if (username.text == "") {
		alert("You must enter a username");
		return;
	}
	if (password.text == "") {
		alert("You must enter a password");
		return;
	}
	if (company.text == "") {
		alert("You must enter a company name");
		return;
	}
	console.log("Now the SQL stuff");
	var sqlstr = "https://myURL/service.asmx/GetTeam_leader?username=" + username.text + "&password=" + password.text + "&companyname=" + company.text;
	console.log(sqlstr);
	http.getJSON(sqlstr).then(function (r) {
		for (i = 0; i < r.length; i++) {
			var userResult = r[i].username;
			console.log(userResult);
		}
		if (userResult == "") {
			Alert("Incorrect login details");
		}
		else if (userResult == username.text) {
			Alert("Login successful");
		}
	});
}

Console.log display the full sqlstr but then doesn’t process the http.getJSON line or anything after.

The JSON returned from the URL is [{“id”:30,“username”:“My Username”}] when I paste the URL into a browser so I know that the JSON is being returned from the API which is an ASP.NET 4 script.

I have tried getJSON and getString neither of which works.


#2

Hi,
Im very limited on time today, do i have no time to fully check this, but i will just paste some http with GET that im using, maybe this will help. In another case i will look at this deeply tommorow.

http.request({
        url: global.Host + '/studios/' + studioId + '/classes/' + classId,
        method: 'GET',
        // i need those headers
        headers: {
            "Authorization": applicationSettings.getString("id"),
            "Content-Type": "application/x-www-form-urlencoded"
        },
    }).then(function (response) {
        result = response.content.toJSON();
        model.set('selectedClasses', result);
        
       // i need some var to be array so i will conver obejct into array so dropdown plugin can access this data
        var seatsList = result.seats_available;
        var seatsArray = seatsList.split(',');
        var allSeats = Object.values(seatsArray)
        model.set('allSeats', allSeats);

        // This will work
        console.log(response)


    }).catch(function (error) {
        alert('Error, please try again.');
    });

#3

OK, my error on this, unsupported URL. I had forgotten to URLEncode the strings being passed to the API.

Thanks for your help.