Question

I came up to this problem where I have a set of links and I need to get the value of the selected one. I am using AJAX to acquire want I want. But is there another way? My current code is not working on other browsers and IOS devices. Anyway this is how it goes:

For example I have 2 dynamically generated links:

Link 1 (Value is Google)

Link 2 (Value is Yahoo)

Say I clicked Link 1. I need to get the value (in my case I used title="Google") of that link which is "Google" and pass that variable to a file_get_contents using variable $linkName. So it will look like:

file_get_contents("http://domain.com/link_contents/includes/**$linkName**")
file_get_contents("http://domain.com/link_contents/includes/**Google**")

I'm using CodeIgniter framework btw.

As of now, I have a working code and used AJAX. But, it's ONLY working with Chrome browser using: Desktop and Android devices. Sadly, it's not working on IOS devices. As far as I can remember, it was working few days ago with IOS but suddenly it's not. I'm in the process of researching on that too if my AJAX code has an effect to IOS devices.

Anyway. It was actually my first time to do AJAX so I apologize my code is quite messy. But this is how I did it:

On my header.php I have the ff:

        $(document).ready(function(){ 
              var getLink = $('.linkClass');
              getLink.each(function(i){
                $(this).click(function(){   
                    var linkName = $(this).attr('title');
                    $.ajax({
                        url: 'http://domain.com/asset/file_get_contents.php',
                        type: "POST",
                        data: { getFromLinkClass: linkName }
                    }).done(function( result ) {
                        $('#divID').html(result);
                    });
                });
            });
        });

On my domain.com/asset/file_get_contents.php file,

  $linkName = $_POST["getFromLinkClass"];
       if ($linkName != null) {
  $links = file_get_contents("http://domain.com/link_contents/includes/$linkName", true); echo $links;      

}

Lastly, on my index.php I can just call the html result which is

<div id="divID"></div>

As I said, this is working but in Chrome only: on Desktop and Android Chrome.

Any suggestions/ideas/comments? Or is there any other way to do this so that it will work on other browsers and IOS devices?

=======================

UPDATE:

I changed my script, disregarded my AJAX code and used pure Javascript instead. It's now working well with other browsers too.

Was it helpful?

Solution

$links = file_get_contents("http://domain.com/link_contents/includes/".$linkName, true);
echo $links;   

Try This.. You must add http:// or https:// as protocol if you want to access external urls. Also concat $linkName after URL

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top