- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was developing barcode scanning app ,the theme of app is to scan the barcode and send it to jsp , in our application server. it is reaching the jsp ,but the response code is not coming as 0,
-------------bcsamp.jsp-------------------
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,java.io.*,java.util.*,java.text.*,javax.sql.*,javax.servlet.*,javax.servlet.http.*,javax.naming.*,javax.naming.directory.*" errorPage="" %>
<%
String bcodstr=request.getParameter("bcstr");
System.out.println("bcodstrval"+bcodstr);
if(!(bcodstr.equals("")))
{
System.out.println("Success"+bcodstr);
out.println("Success");
}
else
{
out.println("Please scan again");
System.out.println("fail"+bcodstr);
}
%>
-------jsp ends here-------------
------------barcode scan function in XDK app-------------
function scan() {
"use strict";
var fName = "scan():";
console.log(fName, "entry");
try {
if (window.tinyHippos) {
thirdPartyEmulator();
console.log(fName, "emulator alert");
} else {
cordova.plugins.barcodeScanner.scan(
function (result) {
console.log(fName, "Scanned result found!");
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
alert("s"+xhttp.readyState);
alert("om"+xhttp.status);
if (xhttp.readyState == 4 || xhttp.status == 200)
{
alert(xhttp.responseText);
}
if(xhttp.readyState != 4 || xhttp.status == 404)
{
alert("Web Service Doesn't Exist");
}
};
//var xhr = new XMLHttpRequest();
var urlo="http://XXX.XX.XX.XX/APPLICATIONSAMP/bcsmap.jsp?bcstr="+result.text;
//var urlo="http://google.co.in";
//alert(urlo);
//xhr.open("GET",urlo,true);
//xhr.send(null);
xhttp.open("GET",urlo, true);
xhttp.send();
/*xhr.onload=function()
{alert("resp status"+xhr.status);
alert("resp status1"+xhr.responseText);
alert("resp status2"+xhr.readyState);
};*/
/*alert("We got a barcode!\n" +
"Result: " + result.text + "\n" +
"Format: " + result.format + "\n" +
"Cancelled: " + result.cancelled + "\n\n" +
"You may use the " + result.format + " - '" + result.text + "' to look up your product in any UPC database like http://www.upcdatabase.com/");*/
},
function (error) {
alert("Scanning failed: " + error);
}
);
}
} catch (e) {
console.log(fName, "catch, failure");
}
console.log(fName, "exit");
}
-------------in this scanning works but response from jsp is not getting.
- Tags:
- HTML5
- Intel® XDK
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Do not use the Emulate tab for testing something like barcode, use a real Android device in conjunction with the Debug tab.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i build the app and installed in my phone and tested it,the response code is coming as 0, it is not getting the response from jsp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Have you tried the barcode sample that is in the "Samples and Demos" section of the "Start a New Project" in the XDK?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is an XDK article somewhere about making AJAX calls. The best thing to do would be to "google" something like "send JSON data to web server in cordova phonegap app"

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page