Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8844637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:32:14+00:00 2026-06-14T11:32:14+00:00

A client-side script takes the text within a text input, wraps it within an

  • 0

A client-side script takes the text within a text input, “wraps” it within an XML block and sends it to a server that stores the information in a MySQL database.

As a first step before wrapping the input value, I escape the “&” characters like so:

var copyright = copyright.replace(/&/g,"&");

The resulting XML data block is sent to the server using jquery’s ajax method:

var copyright = copyright.replace(/&/g,"&"),
    xml = "<request><session>"+session+"</session><space>"+space_id+"</space><view>"+view_id+"</view><copyright>"+copyright+"</copyright></request>",
    url = "hidden URL";

    $.ajax({ 
        type: "POST", 
        url: url,
        contentType: "text/xml; charset=UTF-8", 
        dataType: "xml;charset=UTF-8",
        data: xml
    });

Later after this operation, the content that was previously saved within the database needs to be retrieved and displayed within a web page:

$.ajax({ 
    type: "POST", 
    url: url,
    dataType: 'xml',
    data: xmlString, 
    success: function(xml) { 
          var XML = $(xml);
            // Process the data retrieved
    },
    error: function(jqXHR, textStatus, errorThrown) {
        var XML = $(jqXHR.responseText);
            console.log("error: "+textStatus+"\n"+errorThrown);
    }
});

If an ampersand was typed in the input field and then saved, when trying to load the page that displays the same previously saved content, the ajax call breaks and runs down the error event handler, with the following error:

error: parsererror
Error: Invalid XML: <?xml version="1.0" encoding="UTF-8"?><response><target>    
<target_id>2095466</target_id>    
<plot>20029/13</plot>    
<builder>Lemminkäinen</builder>    
<housing_form>vm</housing_form>    
<block_name></block_name>    
<finnish_year>2013</finnish_year>    
<target_name>As Oy Helsingin Saukonranta</target_name>    
<target_address>Saukonpaadenranta 8</target_address>    
<office_space></office_space>    
<purpose></purpose>    
<reservations></reservations>    
<contacts></contacts>    
<infoflag>2</infoflag>    
<views>    
<view>    
<view_id>2095468</view_id>    
<copyright>B&M</copyright>    
</view>    
</views>    
</target>    
<status>OK</status><errormsg></errormsg></response> 

What is it that I’m doing wrong? Am I escaping the characters wrongly, or is it something else?

This question may seem to be a duplicate, but to me it doesn’t seem like it since the ampersand characters have been escaped prior to being stored. I even tried adding additional (1, then two) amp;s to the escape string, but the result is EXACTLY the same.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:32:16+00:00Added an answer on June 14, 2026 at 11:32 am

    It turns out that the problem actually came from the server (to which I did not have access), the script that handled the requests did not escape the ampersand characters correctly, even though they were on the client-side.
    Bellow is a JavaScript function that escapes all (?) special characters used with XML, just in case someone needs it:

    function escapeXML(string){
    
        var str = string;
        str = str.replace(/\&/g,"&amp;");
        str = str.replace(/\>/g,"&gt;");
        str = str.replace(/\</g,"&lt;");
        str = str.replace(/\"/g,"&quot;");
        str = str.replace(/\'/g,"&apos;");
    
        return str;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a web application that takes a script input from a client-side
I am currently validating user input on server side (PHP). The client side sends
I have a custom validator that points to a Client side script to validate
I'm writing a piece of client-side javascript code that takes a function and finds
Is there any client-side script that would be able to make changes to a
i have a client side jquery script that logs the user off after 5
I need a client-side script to confirm that the Timer's OnTick event can proceed.
I am curious to know if detecting the visitor browser with client-side script is
I understand that the browser does all the work in processing client side scripts
While developer a client side application I ran into an error that I believe

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.