I am getting this error (as per Safari's Web inspector) but I cannot see why. Most reports of this error suggest that it is reading a HTML tag somewhere ... but I cannot see it.
var oReq = new XMLHttpRequest(); //New request object
oReq.onload = function() {
document.getElementById("myConsole").innerHTML = this.responseText;
myData = JSON.parse(this.responseText);
...
The third line of code dumps the responseText onto my webpage (into a DIV called 'myConsole'). This shows what I believe to be standard JSON code ... and contains no '<' characters.
The second line of code tries to parse the responseText and give the '<' token error.
The php data source looks like this:
$rowCount = 0;
do { $rowCount += 1;
$dbCurrentRow = $resultSet->fetch_assoc();
$seats[$rowCount]['room'] = $dbCurrentRow['Room'];
$seats[$rowCount]['seat'] = $dbCurrentRow['Seat'] * 1;
$seats[$rowCount]['x'] = $dbCurrentRow['x'] * 1;
$seats[$rowCount]['y'] = $dbCurrentRow['y'] * 1;
$seats[$rowCount]['name'] = "Joe Bloggs";
$seats[$rowCount]['adno'] = "01234";
$seats[$rowCount]['ev6'] = true;
$seats[$rowCount]['eal'] = true;
$seats[$rowCount]['dpLast'] = "LS";
$seats[$rowCount]['dpCurrent'] = "WA";
$seats[$rowCount]['dpTarget'] = "TG";
$seats[$rowCount]['ma'] = 2 * 1;
} while ($rowCount < $resultSet->num_rows);
echo json_encode($seats);
and the JSON output is this:
{"1":{"room":"35","seat":1,"x":0,"y":0,"name":"Joe
Bloggs","adno":"01234","ev6":true,"eal":true,"dpLast":"LS","dpCurrent":"WA","dpTarget":"TG","ma":2},"2":{"room":"35","seat":2,"x":30,"y":60,"name":"Joe
Bloggs","adno":"01234","ev6":true,"eal":true,"dpLast":"LS","dpCurrent":"WA","dpTarget":"TG","ma":2},"3":{"room":"35","seat":3,"x":60,"y":0,"name":"Joe
Bloggs","adno":"01234","ev6":true,"eal":true,"dpLast":"LS","dpCurrent":"WA","dpTarget":"TG","ma":2},"4":{"room":"35","seat":4,"x":90,"y":90,"name":"Joe
Bloggs","adno":"01234","ev6":true,"eal":true,"dpLast":"LS","dpCurrent":"WA","dpTarget":"TG","ma":2}}
I do not believe it to be a server timing issue since it 'myConsole' dump precedes the error and works fine. It does not look like the JSON is faulty even with a 2d array. The strange thing is if I take the JSON output and save it as 'testDataSample.php' and link my main page directly to it then the same output works flawlessly.
//oReq.open("get", "testDataSample.php", false); //Text JSON output works fine
oReq.open("get", "getData.php", false); // Live from Server ... '<' error
oReq.send();
Any suggestions as to what is wrong, or how I would track this down would be most welcome.
Thank you.
Thank you raghav710 :-)
The console log showed it ... I had some comments at the top of the dataSource.php file which were being included in the echo.
Writing this to my web page ... they were ignored and invisible ... which means I could not see them, and could not see the difference between the two outputs; parsing the comments JSON caused the choke.
I have removed all of the comments at the top of my datasource.php and it work instantly.
Thank you again.
Related
I am using "Iron OCR", something like "Tesseract" to detect and scan certain Text from Screenshots.
Now I have the following error. Every time Iron OCR is used to scan an image for text it tries to access the Iron OCR log file which is somehow still used by the process before. So every time I get the error message that it can't access the log file because it is already in use. Nevertheless the Scan still works and I get a valid result even tho it gives me an exception because of that error.
My program works like this:
it takes a screenshots of certain areas of my screen.
it analyzes that image with Iron OCR and looks for text.
this process repeats itself infinitely.
I have following code:
//------------------------- # Capture Screenshot of specific Area # -------------------------\\
Rectangle bounds3;
Rect rect3 = new Rect();
bounds3 = new Rectangle(rect3.Left + 198, rect3.Top + 36, rect3.Right + 75 - rect3.Left - 10, rect3.Bottom + 30 - rect3.Top - 10);
CursorPosition = new Point(Cursor.Position.X - rect.Left, Cursor.Position.Y - rect.Top);
Bitmap result3 = new Bitmap(40, 14);
using (Graphics g = Graphics.FromImage(result3))
{
g.CopyFromScreen(new Point(bounds3.Left, bounds3.Top), Point.Empty, bounds3.Size);
}
//------------------------- # Analyze Image for Text # -------------------------\\
var Ocr = new IronTesseract();
using (var Input = new OcrInput(result))
{
Input.Contrast();
Input.EnhanceResolution(300);
Input.Invert();
Input.Sharpen();
Input.ToGrayScale();
try
{
//------------------- # This causes the Error - Using Try Catch to Ignore it # -------------------\\
var Result = Ocr.Read(Input);
text = Result.Text;
}
catch
{
}
}
Also removing all the above only using their "1 Line Code" gives the same error message:
var Result = new IronTesseract().Read(#"images\image.png").Text;
I hope someone can help me to figure out what exactly causes that issue.
For starters, I'm seeing two types of problems with my the functionality of the code. I can't seem to find the correct element with the function xmlXPathEvalExpression. In addition, I am receiving errors similar to:
HTML parser error : Unexpected end tag : a
This happens for what appears to be all tags in the page.
For some background, the HTML is fetched by CURL and fed into the parsing function immediately after. For the sake of debugging, the return statements have been replaced with printf.
std::string cleanHTMLDoc(std::string &aDoc, std::string &symbolString) {
std::string ctxtID = "//span[id='" + symbolString + "']";
htmlDocPtr doc = htmlParseDoc((xmlChar*) aDoc.c_str(), NULL);
xmlXPathContextPtr context = xmlXPathNewContext(doc);
xmlXPathObjectPtr result = xmlXPathEvalExpression((xmlChar*) ctxtID.c_str(), context);
if (xmlXPathNodeSetIsEmpty(result->nodesetval)) {
xmlXPathFreeObject(result);
xmlXPathFreeContext(context);
xmlFreeDoc(doc);
printf("[ERR] Invalid XPath\n");
return "";
}
else {
int size = result->nodesetval->nodeNr;
for (int i = size - 1; i >= 0; --i) {
printf("[DBG] %s\n", result->nodesetval->nodeTab[i]->name);
}
return "";
}
}
The parameter aDoc contains the HTML of the page, and symbolString contains the id of the item we're looking for; in this case yfs_l84_aapl. I have verified that this is an element on the page in the style span[id='yfs_l84_aapl'] or <span id="yfs_l84_aapl">.
From what I've read, the errors fed out of the HTML Parser are due to a lack of a namespace, but when attempting to use the XHTML namespace, I've received the same error. When instead using htmlParseChunk to write out the DOM tree, I do not receive these errors due to options such as HTML_PARSE_NOERROR. However, the htmlParseDoc does not accept these options.
For the sake of information, I am compiling with Visual Studio 2015 and have successfully compiled and executed programs with this library before. My apologies for the poorly formatted code. I recently switched from writing Java in Eclipse.
Any help would be greatly appreciated!
[Edit]
It's not a pretty answer, but I made what I was looking to do work. Instead of looking through the DOM by my (assumed) incorrect XPath expression, I moved through tag by tag to end up where I needed to be, and hard-coded in the correct entry in the nodeTab attribute of the nodeSet.
The code is as follows:
std::string StockIO::cleanHTMLDoc(std::string htmlInput) {
std::string ctxtID = "/html/body/div/div/div/div/div/div/div/div/span/span";
xmlChar* xpath = (xmlChar*) ctxtID.c_str();
htmlDocPtr doc = htmlParseDoc((xmlChar*) htmlInput.c_str(), NULL);
xmlXPathContextPtr context = xmlXPathNewContext(doc);
xmlXPathObjectPtr result = xmlXPathEvalExpression(xpath, context);
if (xmlXPathNodeSetIsEmpty(result->nodesetval)) {
xmlXPathFreeObject(result);
xmlXPathFreeContext(context);
xmlFreeDoc(doc);
printf("[ERR] Invalid XPath\n");
return "";
}
else {
xmlNodeSetPtr nodeSet = result->nodesetval;
xmlNodePtr nodePtr = nodeSet->nodeTab[1];
return (char*) xmlNodeListGetString(doc, nodePtr->children, 1);
}
}
I will leave this question open in hopes that someone will help elaborate upon what I did wrong in setting up my XPath expression.
First time poster here for Google Script related services, hopefully I put it in the right place! I'm encountering an error and I can't seem to find the right terminology to look up a solution. Below is the function. Within it I have a variable, string1, that I apply the split to. If I hard-code the value of the string (in the line commented out in the string), then it works and I receive the correct output. If, on the other hand, I try to pass that string into the function from another function, I receive the following error:
"TypeError: Cannot find function split in object Wed Oct 30 2013 09:00:26 GMT-0400 (EDT),danno,ticket,netid,request,mac,Error - Invalid Mac / Mac Not Found."
Note: My call to the function looks like this - formatEmailRow(completeEmailArray[i])
function formatEmailRow(rowToFormat) {
var formattedString = "";
var array1 = [];
var string1 = "";
///////////////////////
string1 = rowToFormat;
//string1 ="10/30/2013 9:00:26,danno,ticket,netid,request,mac,Error - Invalid Mac / Mac Not Found ";
///////////////////////
array1 = string1.split(",| ,|, ");
if (array1 != ""){
for (var i = 0; i < array1.length; i++) {
formattedString = formattedString + " " +(array1[i]);
}}
return formattedString;
}
Please help!
Thanks ahead of time, any advice is appreciated!
-Danno
You're getting that error because .split() isn't a method contained in the type of object you've passed in. Since you're new to this, it's worth a pause to read up on Objects and Methods - this is a quick overview.
You want to receive a String, but it seems that you're not. The problem will be with the code that's calling formatEmailRow().
My guess is that you're passing an array - probably all the cells in a row - but here's how you can check.
Add this line as the first line in your function:
Logger.log("rowToFormat = " + JSON.stringify(rowToFormat));
... then run, with your error. Check the logs - you want to see that you are getting a simple string. If you're getting an array, then you know what you need to fix. (Maybe you want to get the array after all!)
http://localhost/catalog/{"request": "catalog","user_id": "test#gmail.com","purchased": "2"}
here goes my request URL. I need to test my service with a sample URL typed in browser. But it seems that many of the JSON items do not accepted by the server side. if i enter plane text string server works fine. I tried to encode the URL using http://www.albionresearch.com/misc/urlencode.php, but still the errors are there.
May be this is a problem which belongs to tapestry. Else i would like to get some help.
following request works.
http://localhost/catalog/helloworld
tapestry performs its own encoding of parameters within urls, which there is no replica for on the client side.
see org.apache.tapestry5.internal.services.URLEncoderImpl.encode(String)
the reason 'helloworld' works as expected is that there are no 'special characters' so the escaped value would equal 'helloworld' anyway.
So you will either need to encode your json via java using tapestry's URLEncoder or write a client side replica.
that is, if i understand your question properly.
EDIT i was bored so I wrote the client side replica:
/**
* see org.apache.tapestry5.internal.services.URLEncoderImpl.encode(String)
* correct as at tapestry 5.3.5
*/
function tapestryUrlEncodeParameter(input)
{
var safe = "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "01234567890-_.:";
if (input === null)
return "$N";
input = input.toString();
if (input === "")
return "$B";
var output = "";
for (var i = 0; i < input.length; i++)
{
var ch = input.charAt(i);
if (ch === '$')
{
output += "$$";
continue;
}
if (safe.indexOf(ch) != -1)
{
output += ch;
continue;
}
var chHex = ch.charCodeAt(0).toString(16);
while (chHex.length < 4)
chHex = "0" + chHex;
output += "$" + chHex;
}
return output;
}
What do you have server side? Either way you will have to decode your encoded json string on the server side if you want to do it this way.
A better solution might be to use a testing tool of some kind. This could be as simple as a jquery $.get request in a webpage or perhaps you might want to think about a more versatile HTTP client as suggested in this post
today's question involves URLLoader requests using encrypted strings.
when I encrypt a string I get the following result:
1Kx4dfp5OC7ox0zb0lWzzzlnoPLcoPGE1MrAKOtl3h6SPcFmEdpLnUROSKpPrCl70VHRxrKzhsxHHlb1MRp3++JkvYZ++ghBEG2zbVhyaqQ/0+NDrJ+0cLt3g9THe9POohN6Ufcq9TcnmZVvIFXllg4HrjVNfQrhQCNwxuBgWBf2DRc4eq6hKzEgyLdlllQFc9ssUFlPD3wOBqoI22r+7N82sI3pqsQYBq5VlKHHreqD8Cq0gictnTFS3IqepASGARKyuCIPDCa4zE76VeQV5zgvkFfjDww+C1uZ8PUgjH67DKYqUP9a6euf2v1jUpBrREnm4ZbLAXScDjvrJ11rWYyVXOLZy9nhy9qRBQRvdw+tnBThPTmvxaq+LAusF8IbvDpZgMrZ3buvThnXuSBGXZxaja7fk/FIlm4RSliDTSGySiizFHy7dJePXuV0c9MI6ciOYxmEIg64NnhBZtB8wipUDJWOpoytOD2/sNQBenjZbYN8291msYnbBG+alAOQmEBH5Mn4KyW1VQWE2lBGk9ML+SflND8UXfdHz5Q3psOcMZJxSAURKGq5tjA8KlPPOAdQuVPIcysg2/4lV25QGIdDttQVGrkP+ZHZcHIPTLLD+Vml+PJU/OAJGNPGlf3wawUo+bID0FKur8N6tNyu7Pnoocn7plDi6WSJgUAaYjI4=
I send it in, everything seems fine on Flex's end. But when I go to the serverside (logfiles, not allowed to change server-side code) to check what I'm getting, I end up with this:
1Kx4dfp5OC7ox0zb0lWzzzlnoPLcoPGE1MrAKOtl3h6SPcFmEdpLnUROSKpPrCl70VHRxrKzhsxHHlb1MRp3 JkvYZ ghBEG2zbVhyaqQ/0 NDrJ 0cLt3g9THe9POohN6Ufcq9TcnmZVvIFXllg4HrjVNfQrhQCNwxuBgWBf2DRc4eq6hKzEgyLdlllQFc9ssUFlPD3wOBqoI22r 7N82sI3pqsQYBq5VlKHHreqD8Cq0gictnTFS3IqepASGARKyuCIPDCa4zE76VeQV5zgvkFfjDww C1uZ8PUgjH67DKYqUP9a6euf2v1jUpBrREnm4ZbLAXScDjvrJ11rWYyVXOLZy9nhy9qRBQRvdw tnBThPTmvxaq LAusF8IbvDpZgMrZ3buvThnXuSBGXZxaja7fk/FIlm4RSliDTSGySiizFHy7dJePXuV0c9MI6ciOYxmEIg64NnhBZtB8wipUDJWOpoytOD2/sNQBenjZbYN8291msYnbBG alAOQmEBH5Mn4KyW1VQWE2lBGk9ML SflND8UXfdHz5Q3psOcMZJxSAURKGq5tjA8KlPPOAdQuVPIcysg2/4lV25QGIdDttQVGrkP ZHZcHIPTLLD Vml PJU/OAJGNPGlf3wawUo bID0FKur8N6tNyu7Pnoocn7plDi6WSJgUAaYjI4=
at first glance they're the same, but if you check closely, the + gets replaced by a whitespace...
I've even tried switching the + for %2B but on the server-side it gets read as %2B, it isn't converted to a + (flex doesn't seem to function as a browser in this case).
Any kind of insight and help on this matter would be very appreciated.
The requests are being done as follows:
public function callService(callback:String, request:String):void{
var url:URLRequest = new URLRequest(server);
var requestedString:String = handlePluses(request);
url.useCache = false;
url.contentType = contentType;
url.method = method;
trace("sending: " + requestedString);
url.data += requestedString);
serverURL.addEventListener(IOErrorEvent.IO_ERROR, treatIO);
serverURL.dataFormat = URLLoaderDataFormat.TEXT;
serverURL.addEventListener(Event.COMPLETE, loadData);
serverURL.addEventListener(Event.CONNECT, function():void{trace("connected");});
try{
serverURL.load(url);
}catch(e:ArgumentError){trace("ArgError: " + e.message);}
catch(e:SecurityError){trace("SecError: " + e.message);}
catch(e:TimeoutEvent){trace("===========<Timeout>===========");}
}
we fixed this problem by switching the + character with a subset of escaped characters like \&\#.
this might be a problem to others attempting the same thing and trying to keep to a minimum size.