0

I have html file with javascript code the contents of the file are as under: I tried this code on Safari and it was working fine. But when I tried this on Firefox, it’s not working. Can any one suggest how to make it working on firefox.

<html><head></head><body><button type="button" onClick="handleButtonClick();">undo</button> <button type="button">redo</button><select><option value="V1">V1</option><option value="V2">V2</option><option value="V3">V3</option><option value="V4">V4</option><option value="V5">V5</option></select>  <script type="text/javascript">function handleButtonClick(){var xmlHttp, handleRequestStateChange; handleRequestStateChange = function() {if (xmlHttp.readyState==4 && xmlHttp.status==200) { var substring=xmlHttp.responseText; alert(substring); } }      
 xmlHttp = new XMLHttpRequest();xmlHttp.open("GET", "http://csce.unl.edu:8080/test/index.jsp?id=c6c684d9cc99476a7e7e853d77540ceb", true);xmlHttp.onreadystatechange = handleRequestStateChange; xmlHttp.send(null);}</script>
</body>
</html>

if you copy the above code to your system on clicking on undo button u will get the contents but the same code I am inserting through C++ as a string it is not working... what i figured out strange about the above code what that it required enter (return key) to be pressed before xmlHttp = new XMLHttpRequest(); othervise it was not working for html page also. The same thing I implemented in C++ code and the code is not working. The code is as under:

std::string login="<button type=\"button\" onClick=\"handleButtonClick();\">undo</button> <button type=\"button\">redo</button><     select><option value=\"V1\">V1</option><option value=\"V2\">V2</option><option value=\"V3\">V3</option><option value=\"V4\">V4</option><option value=\"V     5\">V5</option></select>  ";

std::string jscriptstring1="<script type=\"text/javascript\">function handleButtonClick(){var xmlHttp, handleRequestStateChange; handleRequestStateChang     e = function() {if (xmlHttp.readyState==4 && xmlHttp.status==200) { var substring=xmlHttp.responseText; alert(substring); } }";

std::string jscriptstring2="xmlHttp = new XMLHttpRequest();xmlHttp.open(\"GET\", \"http://csce.unl.edu:8080/test/index.jsp?id=c6c684d9cc99476a7e7e853d77     540ceb\", true);xmlHttp.onreadystatechange = handleRequestStateChange; xmlHttp.send(null);}</script>";

std::string ret="\n";

login+=jscriptstring1;
login+=ret;
login+=jscriptstring2;

Please can any one suggest what is going wrong?

4
  • 1
    How are you using that string? Do you have some kind of javascript interpreter that you're passing it to? Commented Oct 27, 2010 at 22:14
  • This really strange I just figured out the same code which is html file is also not working. The Thing is that where my C++ code is on ubuntu which is installed using virtual box and I am opening in Firefox... while when I tried the same html file on safari on mac it is working fine... looks like some platform issue Commented Oct 27, 2010 at 22:22
  • The strings aren't identical, could that be the problem? For one example look for value=\"V 5\">. Commented Oct 27, 2010 at 22:27
  • No I don't think so... I tried to use the same HTML code on firefox its not working... may be some browser problem... Commented Oct 27, 2010 at 23:07

1 Answer 1

1

First of all if you are going to create an XMLHttp object for requesting the server in different browsers be sure it is valid in the browser you are using (different browser have different manner to refer the XMLHttp object), normally this object is created as follow:

function getRequestObject(){
    var xmlHttp;
    if (window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
    else if (window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); }
    return xmlHttp;
}

In the other hand, depending on your browser you can debug your script to see what error code is browser returning (if any).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.