0

Why isn't this PHP getting my links array?

function check_links() {

        $matches = $this->input->get('links');


        if($matches == true) {
            echo json_encode('matches is true');
        } else {
            echo json_encode('matches is false');
        } 


        //echo json_encode($matches);

    }

The JS

        var linksStr = $("#links").val();
        var matches = linksStr.match(/\bhttps?:\/\/[^\s]+/gi);

        alert(matches.length);

        for(var i = 0; i < matches.length; i++) {
            alert(matches[i]);
        }

        var links = JSON.stringify(matches);

        $.ajax({
        type: 'GET',
        dataType: 'json',
        cache: false,
        data: links,
        url: 'publishlinks/check_links',
        success:                    
            function(response) {

                alert(response);

            }


        })
1
  • 1
    What does var_dump($_GET) show? Or using a JS debugger, what url is loaded? Commented Aug 9, 2011 at 11:36

1 Answer 1

2

I'm confused a bit with what is trying to be achieved here.
But the JSON.stringify needs to be assigned to a value,

var links = JSON.stringify(matches);

like links

var links = 'links='+JSON.stringify(matches);

Then in your function, $matches should now contain your json-encoded links.
So you can use that,

function check_links() {
  $matches = $this->input->get('links');
  ...
  $matches = json_decode($matches); // do stuff
  ....
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.