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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing "\" from responseText

Status
Not open for further replies.

blah2468

Technical User
Mar 14, 2007
11
CA
Hi there,
I'm processing a text from an XMLHttpRequest. Here's what it looks like:

Code:
  str = req.responseText

When debugging, str looks like this:
str = callHelloFunction(\"param1\", \"param2\")

Now what I need to do is to replace the "\" to "". I'm trying the following:
str = str.replace(/\\/, "")

and I have no luck with this!!! for some readson, none of the "\" get replaced! Your help is much appreciated :)
 
>str = callHelloFunction(\"param1\", \"param2\")
But this line by itself is invalid. What do you mean by putting this line as such? Is it inside a string?
str = "callHelloFunction(\"param1\", \"param2\")"
or what???
 
If you show your REAL code, maybe you'll get REAL help more easily. The problem with contrived code examples is that it typically doesn't show one or more important details.

Lee
 
ok, here's the real code:


Code:
    function DisplayCurrentGFE_StateHandler()
    {
        if (req.readyState == 4)
        {
            if (req.status == 200)
            {
                //We have an html text that displays a list of GFEItems 
               var str; 
               str = req.responseText;
               str = str.replace(/\\/, "");
               
               document.getElementById("divGFEList").innerHTML = str;
            }
            else
            {
                alert("There was a problem retrieving the HTML data:\n" +
                    req.statusText);
            }// if readyState == 200
        }//if radyState == 4
    }// of function
 
I'll just assume that everything else is correct. (I'm pretty sure it's not), your replace will have to be global:

Code:
str = str.replace(/\\/[!]g[/!], "");

About this code:
Code:
str = callHelloFunction(\"param1\", \"param2\")

Why not instead of using \" escaped double quotes, build the string with ' single quotes (not escaped).



[monkey][snake] <.
 
If you replace the contents of a <div> with a function call without placing it inside <script> tags, all you'll get is the text you received and no way to call the function.

Code:
<div id="divGFEList">callHelloFunction("param1", "param2")</div>

Or did you actually want to CALL the function at that point?

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top