VLC Web Plugin and jQuery - javascript

I have wrote an jQuery script for my VLC Plugin, that will hold the link from JSON formated code and past it in the plugin for the rtsp link.
But I have a problem.
$.ajax({
type: "GET",
url: "/api/stream",
processData: true,
dataType: 'text',
cache: false,
success: function (data, textStatus, request) {
stream = jQuery.parseJSON(data);
var vlc = vlcEmb;
var link = stream.rtsp;
var rtsp = link;
vlc.playlist.clear();
vlc.playlist.add(rtsp);
vlc.playlist.play();
}
});
here the code, Mozilla Firefox Firebug show me:
uncaught exception: No such method or arguments mismatch.
How can I fix this?

Related

JQuery AJAX POST produce null params in HttpServletRequest on Liberty profile

I have an older JAX-RS application that I'm running on IBM Liberty profile 16.0.0.4 with the jaxrs-2.0 feature. I'm getting some weird behavior that I can't explain, and need some help.
JAX-RS service code:
#Path("/loadData")
#POST
#Produces("text/plain")
public String loadData(#Context HttpServletRequest request) {
String id = request.getParameter("id");
String email = request.getParameter("email");
// add'l request processing code
}
JQuery code:
$(document).ready(function() {
var reqData = {id:"123456", email:"user#email.com"};
$.ajax({
type: "POST",
cache: false,
url: "http://localhost:9080/jaxrs/loadData",
data: reqData,
contentType: "application/json",
dataType: "json",
timeout: "30",
beforeSend: function() { ... },
success: function(data) { .... },
complete: function(data) { .... }
});
});
JQuery (in IE) Results:
request.getParameter("id") or ("email") = null;
request.toString() = org.apache.cxf.jaxrs.impl.HttpServletRequestFilter#f272c8dc
IOUtils.toString(request.getInputStream) = "id=123456&email=user1%40email.com"
SoapUI Results:
request.getParameter("id") = 123456 and ("email") = user#email.com;
request.toString() = org.apache.cxf.jaxrs.impl.HttpServletRequestFilter#de62638a
IOUtils.toString(request.getInputStream) = ""
I compared the RAW HTTP request in SoapUI and in IE's console, they both appears to be the same, as far as I can tell. So that's really got me confused, both JQuery and SoapUI are performing POST, but seems in IE's case the query stream is not being parsed into parameters, rather just maintained as a string. I've tried to mess around with the contentType and request declaration with no effects. I was originally using JQuery 1.7.1, but I tried on 3.1.1 with no effects. Has anyone seen this before. Any help or insights would be really great, thanks!
Try using "JSON.strigify" for params
$(document).ready(function() {
var reqData = {id:"123456", email:"user#email.com"};
$.ajax({
type: "POST",
cache: false,
url: "http://localhost:9080/jaxrs/loadData",
data: JSON.stringify(reqData),
contentType: "application/json",
dataType: "json",
timeout: "30",
beforeSend: function() { ... },
success: function(data) { .... },
complete: function(data) { .... }
});
});

how to add file data in ajax call without using FormData?

How can i add a file data along with some normal data i.e without form in ajax call?
current i have in my ajax script
$("body").on("click", "#next-step", function(event){
$("#loader").show();
event.preventDefault();
var file = $("#upload_logo")[0].files[0];
$.ajax({
type: 'POST',
url: 'step-two.php',
data:{
name : "my name",
},
file : {upload_logo : file},
contentType: false,
processData: false,
success: function(response)
{
$("#loader").hide();
alert(response);
}
})
});
i found out the solution but it's not the way i would like it to work
event.preventDefault();
var fdata = new FormData()
if($("#upload_logo")[0].files.length>0)
fdata.append("upload_logo",$("#upload_logo")[0].files[0])
$.ajax({
type: 'POST',
url: 'step-two.php',
data:{fdata},
And it works, but my question is what if i just want to add my file in data how can i do this? instead of using FormData() any alternative?
file upload is not possible through ajax. You can upload file, without refreshing page by using IFrame. you can check further detail here
With XHR2, File upload through AJAX is supported. E.g. through
FormData object, but unfortunately it is not supported by all/old
browsers.
FormData support starts from following desktop browsers versions. IE
10+, Firefox 4.0+, Chrome 7+, Safari 5+, Opera 12+
For more detail, see MDN link
Use Form data
var formData = new FormData('form id');
$.ajax({
type: 'post',
async: false,
cache: false,
url: '',
contentType: false,
processData: false,
data: formData,
dataType: 'json',
success: function (response) {
}
});

JSON is not loading from server

I have a JSON file which i want to load end it is working fine when I am trying to load that file locally from my hard drive.
function save(){
$.ajax({
type: "GET",
url: 'cameras.json',
dataType: "JSON",
async : false,
success: function(data) {
var output = data.result["0"].Address;
alert(output);
},
error: function(data) {
alert("Error")
}
});
}
When i want to get access to this JSON file from my server:
function save(){
$.ajax({
type: "GET",
url: 'http://192.168.0.21:8080/json.html?type=cameras',
dataType: "JSON",
async : false,
success: function(data) {
var output = data.result["0"].Address;
alert(output);
},
error: function(data) {
alert("Error")
}
});
}
It's not working and I am getting error script.
What can be issue with that ?
I had the same problem.
Unfortunately, I think that remote (i.e. away from localhost) ajax calls are forbidden - or something similar - for security reasons.
Depending on your purposes, you can resolve the problem with a 2-steps action:
You can call - via ajax - a local server class which loads the remote file via REST web service.I solved this way...

Cordova/Phonegap + Restful Api service + POST method

Can someone please put some light on how to connect your Cordova App to WebServices hosted on a server.
Method: POST method
URL: http://192.168.1.20:3030/Service1.svc
Service Method: Login
Here's what I have been trying(Username-Password verification):
function GetLogin() {
var UName = "12345678";
var UPassword = "12345678";
var jData = { UserName: UName, Password: UPassword };
alert('1');
$.ajax({
type: "POST",
url: "http://192.168.1.20:3030/Service1.svc/AmalatLogin",
data: JSON.stringify(jData),
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
processdata: true,
success: function (msg) {
alert("Start");
document.getElementById("demo").innerHTML=msg.ResponseMessage.toString();
alert("End");
}
});
}
The above code is the javascript part. I have simply called the onClick="GetLogin()" on the submit button.
The problem is the code runs when the html file is being open using localhost( i.e. "http : //(localhost)/ aaa.html" (without spaces) or even by using Google Postman), but fails to do so when I run it from the directory(as in C:\www\aaa.html).
I have been searching for the solution everywhere. Please put some light on whether this is the limitation of technology or do I need to add some plugins.
Basically alert('1') is showing, other alerts are not.
They are all in same network

How to use a javascript ajax api in SAHI

We are using SAHI to do some benchmark tests. Currently they are collecting some times while exercising the application. These times are stored in a text file. We now have an app to collect and analyze this data. We have a restful API in .Net MVC 4. We created a javascript API thinking SAHI should be able to call the javascript methods and go on its merry way. We are having problems figuring out how to get SAHI to use JQuery properly and reference the API.
Javascript API Object:
;
var BenchmarkService = (function (options) {
var settings = $.extend({
serverName: "http://localhost"
}, options || {});
// public api
this.Benchmark = function (benchmarkName) {
var benchmark;
$.ajax({
type: "GET",
url: settings.serverName + '/BenchmarkServices/Services/Benchmark/' + benchmarkName,
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (data) {
benchmark = data;
}
}
);
return benchmark;
};
this.SaveBenchmarkResult = function (benchmarkResultObject) {
var id;
var url = settings.serverName + '/BenchmarkServices/Services/SaveBenchmarkResult';
$.ajax({
type: "POST",
url: url,
data: JSON.stringify(benchmarkResultObject),
async: false,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) { id = data; }
});
return id;};
}
);
We would like be be able to call these methods within SAHI simply by referencing the .js file.
Is this possible?
Can you mention the Sahi version, your java version and os you are using. If you are a pro customer you can directly email to Sahi support team(after all you paid for the support)!
If you are using Sahi Os, let me know the version and I can look if it is possible or not.

Categories

Resources