0

I'm calling a REST Server via a simple function:

$(document).on('click', '#test', function(e){   
    e.preventDefault();
    var name = $(this).data('name'); 
    var path = $(this).data('path');  
    window.location = "http://localhost:80/server/api/v1/files/" + name;        
});

How can I pass aditional data (eg. the path) to my server so that I would be able to grab it in the php request?

public function show($request, $response, $args)
{ 
  // $request contains the path
}

1 Answer 1

1

in Jquery you can you use ajax

$(document).on('click', '#test', function(e){   
    e.preventDefault();
    var name = $(this).data('name'); 
    var path = $(this).data('path');   
    $.ajax({
        'url' : 'http://localhost:80/server/api/v1/files/',
        'method' : 'POST',
        'data' : {
            'name' : name,
            'path' : path
        },
        success(function(data){
            console.log("Sent data");
        })
    });
});
Sign up to request clarification or add additional context in comments.

4 Comments

Just out of curiosity: Is it possibly to achieve the same without ajax?
Yes you can pass the parameters as args
Okay, that would be a possibility but makes no sense because it violates REST best practices in my opinion.
Yes it does violate REST practices

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.