Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Contributor
Posts: 3
Registered: ‎08-09-2010
My Device: Not Specified

BB widget using javascript to insert data into webservice

Hi,

I am creating a BB app using VS 2008 and BB plugin for VS 2008. I am trying to submit data to a webservice and I keep getting this error if I try to pass an object or an string[]. the BB widget is using javascript (based on tutorials on BB dev site) and this is the part of the code where I am getting the error.

 

var myTimeSheet = new Array();

myTimeSheet[0] = document.getElementById('txtprojectName').value;

myTimeSheet[1] = document.getElementById('txtnextWeekLocation').value;

myTimeSheet[2] = document.getElementById('txtcurrentLocation').value;

myTimeSheet[3] = document.getElementById('txtphoneNo').value;

myTimeSheet[4] = document.getElementById('txttimeType').value;

myTimeSheet[5] = document.getElementById('txthrMonday').value;

myTimeSheet[6] = document.getElementById('txthrTuesday').value;

myTimeSheet[7] = document.getElementById('txthrWednesday').value;

myTimeSheet[8] = document.getElementById('txthrThursday').value;

myTimeSheet[9] = document.getElementById('txthrFriday').value;

myTimeSheet[10] = document.getElementById('txthrSaturday').value;

myTimeSheet[11] = document.getElementById('txthrSunday').value;

myTimeSheet[12] = document.getElementById('txtcreateDate').value;


var params = myTimeSheet <- populated with data.
var url = http://[domain]/BBWebService/myService.asmx/InsertTimeSheetArray;
xmlHttp.onreadystatechange = callbackFunction;
xmlHttp.open('POST', url, true);
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(params); <-here i get the error as below

this is the error:
Running at line 156: xmlHttp.send(params);} } }.
Called from line 1: postDynamicData();} } } }.
: TypeError: Invalid type

I can pass data as querystring and it works fine.

any ideas,
Stephen

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: BB widget using javascript to insert data into webservice

I think your params need to be in a name=value pair..

 

So I think it would more look like

 

myTimeSheet["paramName1"] = document.getElementById('txtprojectName').value;

 

etc..

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Contributor
Posts: 3
Registered: ‎08-09-2010
My Device: Not Specified

Re: BB widget using javascript to insert data into webservice

 

Hi Tim,

 

As suggested I tried to use Name/Value pair and I still get the error

 

var myTimeSheet = new Array();  
myTimeSheet["projectName"] = document.getElementById('txtprojectName').value;

.... etc

 

var params = myTimeSheet;
alert(myTimeSheet["projectName"]);
           
var url = "http://[IPAddress]/BBWebService/myService.asmx/InsertTimeSheetArray";
xmlHttp.onreadystatechange = callbackFunction;
xmlHttp.open('POST', url, true);       
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(params); 

 

 

This is my WebService in .NET

[WebMethod(CacheDuration = 30,
                    Description = "Input parameter is a string[] array and returns a string.")]
public string InsertTimeSheetArray(string[] currentTimeSheet)
        {           
            int result = [WhateverClass].insertData(currentTimeSheet[1], currentTimeSheet[3], currentTimeSheet[0], currentTimeSheet[2], currentTimeSheet[4], int.Parse(currentTimeSheet[5]),int.Parse(currentTimeSheet[6]), int.Parse(currentTimeSheet[7]),int.Parse(currentTimeSheet[8]), int.Parse(currentTimeSheet[9]), int.Parse(currentTimeSheet[10]), int.Parse(currentTimeSheet[11]), currentTimeSheet[12]);
            if (result == 1)
                return "Success";
            else
                return "Failed";
           
        }

 

I still get the error:
Running at line 156: xmlHttp.send(params);} } }.
Called from line 1: postDynamicData();} } } }.
: TypeError: Invalid type

please advice