Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xmlhttp.open gives me "Invalid syntax" error

Status
Not open for further replies.

amigo02

Programmer
Feb 19, 2003
109
I have the following code in a javascript function

function fnAction(oButton){
var objXMLHTTP= new ActiveXObject("Msxml2.XMLHTTP.4.0");
var objXmlDOM=new ActiveXObject("Microsoft.XMLDOM");

varStr="somePage.aspx";

try {
objXMLHTTP.open("POST",varStr ,false);
}
catch (errorObject)
{
alert(errorObject.description)
}
objXMLHTTP.send("");

//process the xml
...
...

objXMLHTTP=null;
}
when the page first loads and I click a button to call this function it works perfectly. But when I click the button second time without loading the page again I get "Invalid syntax" at the objXMLHTTP.open statement.
 
Try only instantiating the ActiveX Objects once when the page loads, but do the rest of the code when the button is pressed. Something like this:

Code:
function pageInit() {
    var objXMLHTTP= new ActiveXObject('Msxml2.XMLHTTP.4.0');
    var objXmlDOM=new ActiveXObject('Microsoft.XMLDOM');
}

function fnAction(oButton) {
    varStr = 'somePage.aspx';

    try {
        objXMLHTTP.open('POST', varStr, false);
    }
    catch (errorObject) {
        alert(errorObject.description);
    }
    objXMLHTTP.send('');

    //process the xml
    ...
    ...

    objXMLHTTP = null;
}

I haven't tried it, but it would be the first thing I would try if i had the same problem ;o)

Hope this helps,
Dan
 
Infact initially it was just like that and I changed to try different things.

After wasting so much time I realized why it was happening but I still don't have solutions.

I have two "TEXTAREA" elements on the page in a table as follows

...
<TD style="TABLE-LAYOUT: fixed; VERTICAL-ALIGN: baseline; WIDTH: 393px; CURSOR: text; LINE-HEIGHT: 3mm; HEIGHT: 128px; TEXT-ALIGN: left">

<TEXTAREA id="Marks" style="FONT-SIZE: smaller; WIDTH: 392px; BORDER-TOP-STYLE: none; LINE-HEIGHT: 3mm; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; LETTER-SPACING: normal; HEIGHT: 114px; BORDER-BOTTOM-STYLE: none" rows="7" cols="46">xxxxx</TEXTAREA>
</TD>

<TD style="HEIGHT: 128px">
<TEXTAREA id="Comments" style="FONT-SIZE: smaller; WIDTH: 286px; BORDER-TOP-STYLE: none; LINE-HEIGHT: 3mm; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; LETTER-SPACING: normal; HEIGHT: 88px; TEXT-DECORATION: none; BORDER-BOTTOM-STYLE: none" rows="5" cols="33"></TEXTAREA>
</TD>
...


and I have the following lines to retrieve values from these two TEXTAREA elements and pass them with all other values into the xmlhttp object;

varStr="somePage.aspx?";
varStr+="Marks=" + escape(document.Form2.Marks.value)
varStr+="&Comments=" + escape(document.Form2.Comments.value)

So that's where the problem is. The values from these elements are causing the "Invalid syntax" problem. Because once I clear them and click on the button it executes nicely again and again.
 

This:

Code:
varStr+="&Comments=" + escape(document.Form2.Comments.value)

should actually have the ampersand escaped to be considered a valid URL:

Code:
varStr+="&amp;Comments=" + escape(document.Form2.Comments.value)

Hope this helps,
Dan
 
OK I figured out what's going on, it happens because the querystring exceeds the 2056k limit.

Is there a way around to this problem.

In other words the size of the string that I try to pass in POST operation is the problem.

I knew there was a limitation but but until now I never had such a problem with any module. But this one has alot of fields and naturally it exceeds 2056k limit.
 

Is there really no way you can restructure things to avoid posting over 2Mb of data? That really is a considerable amount of data to be sending in a form submission - more than would fit on 1 floppy disk!

Perhaps you could give us some background information that may enable a better / less byte-hungry solution to be proposed?

Dan
 
Sorry it is supposed to be 2056 bytes not kilobytes.
Another thing I found a solution to go over this limit.

Put following in Web.config file

<httpRuntime maxRequestLength="8096"
useFullyQualifiedRedirectUrl="true"
executionTimeout="45"/>

that's all there is to it. This only took 3 days to resolve it, so not bad at all!!!!!

Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top