1

I am working on my jquery script to extract the filename to output them in the element when i am fetching the data from ajax call.

When I try this:

var photoFilename = filename.split('filename: ');
$('#photo_filename').text(photoFilename1);
$('#photo_dialog').show();

I will get something like this:

noname.gif attid: 0.2

I have also tried this:

var photoFilename = filename.split('attid: ');

And I have also tried this:

var photoFilename = filename.split(attid);

I will get this:

 filename: noname.gif attid: 0.2 filename: what-is-bootstrap.png

I have tried to use .replace function to remove the attid: 0.2 but my variable attid are showing a different string so it is hard for me to remove the string for 0.2 when I have 0.1 string.

Here is what I want to achieve:

noname.gif

Here is the full output:

attid: 0.1 filename: noname.gif
attid: 0.2 filename: what-is-bootstrap.png

Here is the full code:

$.ajax({
    url: 'readMail.php',
    type: 'POST',
    data : {
        mailfolder: mailfolder, 
        email_number: email_number,
        folder: folder,
        readmail: readmail,
        total: total_index
    },
    dataType: 'json',

    success: function(res) {
        filename = res.emailBodyMessage.attached_files;
        var photoFilename = filename.split('filename:');
        $('#photo_filename').text(photoFilename1);
        $('#photo_dialog').show();
   }
});

What I am trying to achieve is if I have the string 0.2 using the variable attid, I want to fetch the filename what-is-bootstrap.png. If I have the string 0.1 using the variable attid, I want to fetch the filename noname.gif and so on.

Can you please show me an example how I can fetch the filename when my variable attid show the string like 0.1, 0.2 or whatever it is?

Thank you.

Robert Jones
  • 390
  • 3
  • 18

0 Answers0