douruyun8153 2014-10-08 04:35
浏览 38
已采纳

Ajax Jquery和php:如何控制反馈?

Let's suppose you're sending data through ajax. The server will process it (PHP) and sends a feedback that you can grab using Complete: function(data) { //WRITE HTML TO DIV $('#somehing').html(data) } The question is: is there a way to modify data (edit, delete) before passing it to an html element?

Here's a simple example of what I mean :

//php side
echo 'Invalid email';
echo 'Enter your username';
echo 'fine';
echo 1;
echo 2;


// Jquery and Ajax
$.ajax({
type: 'POST',
url: 'render.php',
data:values,
complete: function(data) {
$('#something').html(data) /* all those messages in php will be printed 
into #something including the numbers. how to delete or edit those numbers 
from appearing in #something? */
}
});
  • 写回答

2条回答 默认 最新

  • dtpwra8456 2014-10-08 05:42
    关注

    Try this to remove the numbers like,

    complete:function(data){
       data=data.replace(/\d+/,''); // Regular expression without quotation marks.
       // or you can replace the something text like
       // $('#something').text(function(){
       //     return this.innerText.replace(/\d+/,'');
       // });
       alert(data);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)