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 7444499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:31:39+00:00 2026-05-29T11:31:39+00:00

Have posting working wonderfully, and reading the response happily EXCEPT when one of the

  • 0

Have posting working wonderfully, and reading the response happily EXCEPT when one of the data elements has new lines in it (\n). Hours and hours of googling, and I’m completely confused and baffled at this point. What am I missing, or doing wrong with this to be able to receive a data element that has newlines in it? In this particular case I’m going to display it to the user, so
tags are fine, but I’d originally wanted it to be in a for editing and any newlines returned give me errors.

 .click(function() {
     var $form = $("#product_data_form");
    var dataString = $form.serialize()
    $.ajax({
        type: "POST",
        url: "utility02a.php",
        data: dataString,
        dataType: "json",
        success: function(server_response)
        {
            $("div#my_results").append(server_response.MyTextWithNewLines);
        }
    });

Then, on the server, in PHP (and this works as expected unless there are \n’s in the response

 echo '{';
 echo '"status":"'.$status.'",';
 echo '"MyTextWithNewLines":"'.json_encode($sometext).'"';
 echo '}';

I’m sure it’s an encoding issue somewhere along the line, but my eyes are spinning trying to understand what to encode how, where and when.

In short, the data returned should be able to be in a textarea for editing, with the new lines properly represented in the input area for the user.

  • 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-05-29T11:31:43+00:00Added an answer on May 29, 2026 at 11:31 am

    You may want to use json_encode instead, as I use that with newlines with no issue. Build an associative array of the data you want to encode. The keys of the array will be the json objects members once it’s decoded on the client side:

     <?php
         $data = new Array(             'status' => $status,
                            'mytextwithnewlines' => $sometext
                          );
    
         echo json_encode($data);
     ?>
    

    That should get it for you!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem POSTing data via HTTPS in Java. The server response is
I have forms posting data from instances of a particular abstract class: public abstract
I m working on django view.I m posting a form which has a param
My first delve into working with JSON data. I have a bit of experience
I have a working Action and JSP form that I'm using for creating new
I am working on a new application and I have a need to use
I have a script which is posting some form data to a Quickbase and
Ok this may be a simple question. I have a working concept of posting
I have issue with letters when posting data to server NSString *url = [NSString
I have people posting their website address but variations are posted such as: theirsite.com

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.