i have installed rtMedia on my web-site(which i have already installed buddypress) and now i’m trying to write an android application using the api of rtMedia but when i try to do a request like http://example.com/rtmedia_api/wp_login/?username=USER&password=PASS it display me “NOT FOUND”.
I have also tryed using the endpoint, like this http://example.com/wp-admin/admin-ajax.php/rtmedia_api/wp_login/?username=USER&password=PASS in this case it display me “0″.
I don’t understand how to use this api with json code to do json request.
I use also other plugin which have api and to perform a request i just need to type something like this http://example.com/api/?json=get_recent_posts/?cookie=COOKIE
Why it dosen’t work whith rtMedia api??
(sorry for my bad english :D )
This isn't the way rtMedia API will work.
Please check this doc about rtMedia JSON API.
For any queries regarding rtMedia, you can create a support request here
The rtmedia api plugin requires you to submit it via POST request (even though the confusing 'documentation' tells you otherwise with some functions). The easiest way to go about this is to create a form using the method="POST" and action="yourhost.domain/wordpress/wp-admin/admin-ajax.php". Another way to go about this is by using javascript (which I presume you will be using) and creating a formdata object like so: var formData_rtmedia = new FormData(); and appending (for example wp_login) the strings of your input field like this:
// _(id) is a function that returns document.getElementById(id)
var data1 = _('wp_login_input1').value;
var data2 = _('wp_login_input2').value;
if(data1 != undefined && data1 != '') {formData_rtmedia.append('username', data1);}
if(data1 != undefined && data1 != '') {formData_rtmedia.append('password', data2);}
Using the if dataX not equals undefined and not equals empty string check ensures the fields that are optional can be empty and won't populate the postdata object with empty or null values. The object can be sent using ajax (aka an XMLHttpRequest object) like this:
var xhr;
function ajax(method, url, async, formData) {
if(window.XMLHttpRequest) {xhr = new XMLHttpRequest();}
else {xhr = new ActiveXObject('Microsoft.XMLHTTP');}
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
if(xhr.status != 200) {/* handle error */}
else {/* handle response */}
} else {
// display ajax loader or do something fancy
}
}
xhr.open(method, url, async);
xhr.send(formData);
}
and calling it in your rtmedia javascript file like so: ajax('POST', url, true, formData_rtmedia);
Related
I am using Angular4 with TypeScript version 2.2.2
My web app is running fine when I call JSON with Filters but my NativeScript app fails when I call the Filter Values as an Object but works fine when I call filter values as a string.
Error Response with status: 200 for URL: null
THIS WORKS
https://domainname.com/api/v1/searchevents?token=057001a78b8a7e5f38aaf8a682c05c414de4eb20&filter=text&search=upcoming
If the filter value and search value is STRING it works whereas if they are objects as below, it does not work
THIS DOES NOT WORK
https://api.domainname.com/api/v1/searchevents?token=057001a78b8a7e5f38aaf8a682c05c414de4eb20&filter={"limit":"12","skip":"0"}&search={"search":"","latitude":"","longitude":"","categories":"","address":"","type":"upcoming"}
The Code I used is below
getData(serverUrl, type, skip_limit) {
console.log(serverUrl);
let headers = this.createRequestHeader();
let token_value = localStorage.getItem('access_token')
let url;
var filter;
filter = '{"limit":"10","skip":"0"}'
url = this.apiUrl + serverUrl + '?token=' + token_value + '&filter=' + filter
return this.http.get(url, { headers: headers })
.map(res => res.json());
}
The URL as formed above for the API is fine and works fine. Yet the error comes Error Response with status: 200 for URL: null
CAN ANYONE HELP ME SOLVE THIS?
Looks like the issue is the "filter" values are of different type and from what you mentioned as what worked, your service is expecting a string and not an object/array. So it fails to send the proper response when it gets one. With an object in the URL, you may have to rewrite the service to read it as an object (parse the two attributes and get them individually)
To make it simple, you can make these two as two different variables in the URL. like below,
https://api.domainName.in/api/v1/oauth/token?limit=10&skip=0
Be more precise in whats happening in your question,
1) Log the exact URL and post it in the question. No one can guess what goes in "text" in your first URL.
2) Your URL which you mentioned as worked have "token" as part of path, but in the code, its a variable which will have a dynamic value from "token_value".
3) Post your service code. Especially the signature and input parsing part.
Got the solution:
All you have to do is encode the Filter and Search Parameters if it is an Object or Array using Typescript encodeURI()
var filter = '{"limit":"12","skip":"0"}'
var search = '{"search":"","latitude":"","longitude":"","categories":"","address":"","type":"upcoming"}'
var encoded_filter = encodeURI(filter);
var encoded_search = encodeURI(search);
url = this.apiUrl+serverUrl+'?token='+token_value+'&filter='+encoded_filter+'&search='+encoded_search
I am trying to send some data from Dart to PHP...
This is the code i am using to send the data from Dart:
button.onClick.listen((e) {
var req = new HttpRequest();
req.onReadyStateChange.listen((HttpRequestProgressEvent e) {
if (req.readyState == HttpRequest.DONE) {
print('Data submitted!');
}
});
req.open('POST', form.action);
req.send('hello from dart');
});
In my PHP file I am trying to use the string i have send from dart, but count($_POST) returns 0. $_POST seems to be empty...
Dart code DOES trigger the php script and 'Data submitted' is printed...
This is actually related to your PHP configuration. You can access the POST'd data with PHP's reserved variable: $HTTP_RAW_POST_DATA However the preferred method is to use php://input
I am very new to Dart, but you can use FormData in the send. So a quick and dirty way could be.
var data_form = new FormData(query('#My_form'));
button.onClick.listen((e){
var request = new HttpRequest():
request.open('POST', 'http://Localhost/form_data.php');
request.send(data_form);
We have a web page that shows reports, with a dynamic set of filters.
A user selects a named report and the page gets the valid filters from WebApi as a JSON list. The user can select the filters, which then shows the results in a grid (again via a WebApi call). All fine so far
Now we to allow a download of the data as a file (e.g. Excel) and have hit a problem.
We want to send a HttpPost (but not an AJAX post) with the JSON filter data, so that the browser downloads a file. We cannot use a JQuery $.ajax or $.post, as the data is returned in a callback, and not as a browser handled download.
We experimented with a tag and a submit button, but searching StackOverflow suggest this only supports sending data as name-value pairs, rather than a JSON body. Unless you know different?
It seems the simplest method would be to use a with a single hidden input field, with the contents of the JSON encoded in a hidden control, and then manually deserialize this at the server?
You could add an html form and loop through the object to add as name value pairs to the form.
var query = {},
$form = $("<form>")
.attr("method", "post")
.attr("action", 'pathtoservice');
$.each(query, function (name, value) {
if (typeof (value) === "number" || typeof (value) === "string") {
$("<input type='hidden'>")
.attr("name", name)
.attr("value", value)
.appendTo($form);
}
else if (typeof (value) === "object") {
$.each(value, function (i, item) {
$("<input type='hidden'>")
.attr("name", name)
.attr("value", item)
.appendTo($form);
});
}
});
$form.appendTo("body");
$form.submit();
Can some one help or explain to me how this works please?
i have in my view:
<script type="text/javascript">
var jqxhr = $.getJSON("<%= Url.Action("GetTrainingModulePoints" , "Home") %>", function (json) {
console.log(json);
});
</script>
GetTrainingModulePoints should return 4 rows each containing a value for interactiontype and a value for points
in the console log i just get [object object]?
how can i see what is in the variable json?
http://imageshack.us/photo/my-images/542/firebug.png/
thanks
Look at the Network tab in FireBug or similar javascript debugging tool. There you will see the AJAX request and all you have to do is expand the request and look at the response.
Here's for example how that might look like in FireBug for a sample AJAX request:
And if you click on the JSON tab you will see the output formatted as a JSON object where you could expand/collapse the properties.
If for some very weird reason you cannot use a javascript debugging tool in your web browser (I don't know even know how you could be developing a web application, but ...) you could use the JSON.stringify method that's built into modern browsers:
var jqxhr = $.getJSON("<%= Url.Action("GetTrainingModulePoints" , "Home") %>", function (json) {
alert(JSON.stringify(json));
});
And if you are not using a modern browser which doesn't have the JSON.stringify method natively built-in you could still reference the json2.js script to your page.
UPDATE:
OK, it seems that your confusion comes from the fact that you are getting {"success":true} whereas you were expecting to get the rows from your stored procedure. I know this because I answered your previous question.
Here's how your controller action look like:
[HttpGet]
public JsonResult GetTrainingModulePoints()
{
var currentUser = ZincService.GetUserForId(CurrentUser.UserId);
ZincService.TrainingService.GetTrainingModulePoints(currentUser.UserId);
return Json(new { success = true }, JsonRequestBehavior.AllowGet);
}
As you can see in this controller action you are always returning success = true. If you want to return the results from your stored procedure you could do this:
[HttpGet]
public JsonResult GetTrainingModulePoints()
{
var currentUser = ZincService.GetUserForId(CurrentUser.UserId);
var modulePoints = ZincService.TrainingService.GetTrainingModulePoints(currentUser.UserId);
return Json(
new {
success = true,
modulePoints = modulePoints
},
JsonRequestBehavior.AllowGet
);
}
Here I assume that your TrainingService.GetTrainingModulePoints method is actually returning some object. If this is not the case you will have to explain what those methods are doing and how do you expect to get the output.
I have a simple Backbone.js/Bootstrap front end in HTML5 with a Node.js/Restify backend. I am setting cookies in a header response from the server as below:
res.setHeader("Set-Cookie", ["token=ninja", "language=javascript"]);
On the client side, I am making a REST call as
var response = this.model.fetch().success(function(data){
//success
}).error(function(data){
//error
}).complete(function(data){
//complete
});
that callsback a parse method in the model.
How can I read the cookie value in the model?
Include Cookie.js.
You can then reference individual cookies like this:
var token = Cookie.get('token')
# token == 'ninja'
Here is what I figured out. My application has two components - the HTML/js from one domain that talks to a REST sevice on another domain (and therefore is cross-domain.) Because the cookie is set from REST, it appears is not readable across domains. So the web page will not store the cookie even though the server is sending it. One alternative is to use local cookies or use the technique illustrated by http://backbonetutorials.com/cross-domain-sessions/.
Assuming you are using jQuery with Backbone, you can get the headers by defining the parse function in your model by calling getAllResponseHeaders or getResponseHeader:
var model = Backbone.Model.extend({
// the rest of your model
parse: function(resp, xhr) {
var allHeaders = xhr. getAllResponseHeaders();
var cookieHeader = xhr. getResponseHeader("Set-Cookie");
// do something with the headers
return resp;
}
});