Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deal with the problem of line wrapping in the return value of ajax asynchronous submission

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how to deal with the line break problem in the return value of ajax asynchronous submission. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Background introduction:

The function that needs to be realized is to select a category in the drop-down box, submit it to PHP and return the member names under the category according to the selected category, and the return value of each member name will be displayed in textarea in the form of newline.

Html Code:

Type: select the type, Chief on Duty, Chief Duty Officer.

Members:

JQuery Code:

$(document) .ready (function () {$("# typeduty") .change (function () {var type = $("# typeduty"). Val (); $.post ("setduty_do.php", {'cid': type,}, function (data,status) {newData = data.replace (/\ r\ nCPG); $("# names") .html (newData);})

PHP Code:

If ($type) {switch ($type) {case "1": $arrs = getChiefList (); break; case "2": $arrs = getDirectList (); break; case "3": $arrs = getAttendantList (); break; default: break;} $arr_names = ""; foreach ($arrs as $arr) {if (strlen ($arr [1]) > 2) {$arr_names.= $arr [1]. "\ n";} echo $arr_names;}

The value returned in the php code is directly marked with a newline "\ n". The newline symbols of IE and FF in textarea are both "\ n". Note in the return value of jQuery processing, use the

NewData = data.replace (/\ r\ nAccording to ggamma')

The result returned by processing is used to remove the initial newline symbol, and the value returned by Ajax is automatically accompanied by a newline. This comes with Ajax itself.

This is the end of this article on "how to deal with the problem of line wrapping in the return value of ajax asynchronous submission". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report