Jquery plugin: Jplayer dynamic playlist - jplayer

please somebody help me with this... im using jplayer plugin to play music on my website.
javascript:
var cssSelector = {
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
};
var playlist = []; // Empty playlist
var options = {
swfPath: "/js",
supplied: "mp3"
};
var myPlaylist = new jPlayerPlaylist(cssSelector, playlist, options);
$.ajax({
url: 'process/getmusics.php',
cache: true,
async: false,
type: 'post',
data:{
category: category,
moodrate: rate,
},success:function(data){
alert(data);
var music = $.parseJSON(data);
myPlaylist.add(data);
}
});
php:
$sql = "SELECT
`musics`.`file_name` as mp3
FROM
`categories`
INNER JOIN `musics`
ON (`categories`.`id` = `musics`.`category`)
WHERE (`categories`.`category_name` =?
AND `musics`.`rate` =?)";
$result = $con->prepare($sql);
$result->bindParam(1, $category);
$result->bindParam(2, $rate);
$data=0;
if($result->execute()){
while($r = $result->fetchAll(PDO::FETCH_OBJ)){
$data = $r;
}
echo json_encode($data);
}
now my ajax return a correct data but the problem is in my jplayer..
generated error by console:
Uncaught TypeError: Cannot use 'in' operator to search for 'length' in [{"mp3":"Passenger - Let Her Go.mp3"},{"mp3":"Secondhand Serenade - Maybe.mp3"}]
please help..

Related

Netsuite Print Button - "error.SuiteScriptError","name":"MISSING_PDF_PARAMETERS",

I have created a print button to print an advanced PDF from a sales order, so the client can get a commercial invoice generated. I have done this for other clients with success but I am running into an issue where the standard templates will print a pdf from the button but the customized ones will not. Where am I going wrong in the code here:
Suitelet:
function onRequest(context) {
var custom_id = context.request.parameters.custom_id;
var tempid = context.request.parameters.tempid;
log.debug("id", custom_id);
log.debug("id", context.request.parameters);
var pdfFileName = "Commercial Invoice";
var renderer = render.create();
var content = renderer.addRecord({
templateName: 'record',
record: record.load({
type: record.Type.SALES_ORDER,
id: custom_id
})
});
renderer.setTemplateByScriptId(tempid);
var pdfFile = renderer.renderAsPdf();
log.debug ("pdf", pdfFile)
context.response.writeFile(renderer.renderAsPdf(),true);
}
return {
onRequest: onRequest
}
});
Client Script:
function onButtonClick() {
var suiteletUrl = url.resolveScript({
scriptId: 'customscript_commercialinv_so_sl',
deploymentId: 'customdeploy_commercialinv_so_sl',
returnExternalUrl: true,
params: {
custom_id: currentRecord.get().id, tempid: "CUSTTMPL_109_4753601_SB1_795"
},
});
window.open(suiteletUrl,"_blank");
}
exports.onButtonClick = onButtonClick;
exports.pageInit = pageInit;
return exports;
});
My user script looks solid. I am getting this error when I direct the Client script to a custom template as referenced above:
{"type":"error.SuiteScriptError","name":"MISSING_PDF_PARAMETERS","message":"Missing parameters required to generate PDF","stack":["renderAsPdf(N/render)","onRequest(/SuiteScripts/MegWebb/cust_SOprinttemplate_SL.js:28)"],"cause":{"type":"internal error","code":"MISSING_PDF_PARAMETERS","details":"Missing parameters required to generate PDF","userEvent":null,"stackTrace":["renderAsPdf(N/render)","onRequest(/SuiteScripts/MegWebb/cust_SOprinttemplate_SL.js:28)"],"notifyOff":false},"id":"","notifyOff":false,"userFacing":false}
Any help would be much appreciated!

Creating form in netsuite using suitscript 2.0

var formData = new FormData();
formData.append("name", "John");
formData.append("age", "31");
for (var value of formData.values()) {
log.debug(value);
}
but when i want to log form values using formData api. It's giving below error.
ReferenceError: "FormData" is not defined.
FormData is a client side API managed under XMHttpRequest
UserEvent scripts are server side scripts with no browser based APIs available at all.
So you could use FormData in a client script to send info to a Suitelet or RESTlet but it's not present in a UserEvent script.
If you want to create a form in a Suitelet using SS2.0 you can use the following as a sample:
/**
*#NApiVersion 2.x
*#NScriptType Suitelet
*/
define(["N/log", "N/redirect", "N/runtime", "N/ui/serverWidget", "N/url", "./kotnRECBCFilters"],
function (log, redirect, runtime, ui, url, kotnRECBCFilters_1) {
function showPropertiesForm(context) {
var form = ui.createForm({
title: 'Property Trust Ledger'
});
var req = context.request;
var fromLoc = form.addField({
id: 'custpage_loc',
type: ui.FieldType.SELECT,
label: 'For Property',
source: 'location'
});
fromLoc.updateLayoutType({ layoutType: ui.FieldLayoutType.NORMAL });
fromLoc.updateBreakType({ breakType: ui.FieldBreakType.STARTCOL });
if (req.parameters.custpage_loc) {
fromLoc.defaultValue = req.parameters.custpage_loc;
}
var notAfterDate = form.addField({
id: 'custpage_not_after',
type: ui.FieldType.DATE,
label: 'On or Before'
});
if (req.parameters.custpage_not_after) {
notAfterDate.defaultValue = req.parameters.custpage_not_after;
}
form.addSubmitButton({
label: 'Get Detail'
});
//... bunch of stuff removed
context.response.writePage(form);
}
function onRequest(context) {
if (context.request.method === 'POST') {
var currentScript = runtime.getCurrentScript();
var params = {};
for (var k in context.request.parameters) {
if (k.indexOf('custpage_') == 0 && k.indexOf('custpage_transactions') == -1) {
if ((/^custpage_.*_display$/).test(k))
continue;
params[k] = context.request.parameters[k];
}
}
redirect.toSuitelet({
scriptId: currentScript.id,
deploymentId: currentScript.deploymentId,
parameters: params
});
return;
}
showPropertiesForm(context);
}
exports.onRequest = onRequest;
});

How to get a text / return(JSON ) in my API code with Watson?

In my example,
If the user clicks the button "Yes" Will return a conversation text. But I'd like it to return a value from my output, the return from my AJAX Post example, which is currently only coming from the "alert (output.request.number)".
How to make? Follow the codes:
In the conversation Intents: #goodbye and two entities: #goodbye:yes and #goodbye:no. If my client-side recognize the intent and user clicks the button "yes", will return something.
My JSON Advanced (Conversation Service)
{
"output": {
"text": "You can finish the conversation? \n \n
<button id=\"button-yes\" onclick=\"OneFunction();\">Yes</button>
<button id=\"button-no\" onclick=\"OtherFunction();\">No</button>"
}
}
I need the return of alert(output.request.number) to come in Watson's conversation flows if the user clicks on the button.
The JS code:
function OneFunction(firstParameter, secondParameter){
console.log(firstParameter);
$.ajax({
type: 'POST',
dataType: 'json',
contentType: "application/json",
url: 'http://xxxxxxxxxxxxxxxxxxxxxxxx/request/create',
data: JSON.stringify({
"dataOne":firstParameter,
"synchronize":false,
}
}),
success:function(output, input, response) {
console.log(output);
// alert(output.request.number);
var responseText = null;
var outputTest = {};
outputTest = output.request.number;
var latestResponse = Api.getResponsePayload();
// console.log(latestResponse);
var context = latestResponse.context;
Api.sendRequest = ("Yes", + outputTest); // THIS RETURN one number of request
}
I try it and work, the error is just a , between ("Yes" + outputTest);
But yours information was essential to this, thanks, #Michal Bida and #timd. :
success:function(output, input, response) {
console.log(output);
// alert(output.request.number);
var responseText = null;
var outputTest = {};
outputTest = output.request.number;
var latestResponse = Api.getResponsePayload();
// console.log(latestResponse);
var context = latestResponse.context;
Api.sendRequest = ("Yes" + outputTest); // THIS RETURN one number of request

Kendo Grid - problems with search in database

My controller like this:
[HttpPost]
public ActionResult Error_Search([DataSourceRequest] DataSourceRequest request, object[] ParaSearch)
{
object[] obj = new object[5];
obj[0] = Convert.ToInt32(ParaSearch[0]);
obj[1] = ParaSearch[1].ToString();
obj[2] = Convert.ToDateTime(ParaSearch[2]).AddDays(-10);
obj[3] = Convert.ToDateTime(ParaSearch[3]);
obj[4] = ParaSearch[4];
List<Vsoft.Lists.Model.SYS.SYS_Error> lst = new List<Vsoft.Lists.Model.SYS.SYS_Error>();
ResultMessage result = new Vsoft.Lists.DALEntity.SYS.DAL_Error().SelectToList(ref lst, obj);
return Json(lst.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
It will return Json(lst) correct.. but I can't bind it to datasource and refresh Grid after Ajax Call like this :
var requestData = { ParaSearch: arrObject };
$.ajax({
url: '#Url.Content("~/Error/Error_Search")',
data: JSON.stringify(requestData),
type: 'POST',
traditional: true,
dataType: 'json',
contentType: 'application/json; charset=utf-8',
error: function (xhr) {
result = false;
alert('Error: ' + xhr.statusText);
},
success: function (lst) {
var grid = $("#Grid").data("kendoGrid");
grid.dataSource.data(lst);
grid.refresh();
},
async: true,
processData: false,
cache: false
});
Can AnyOne help me to solve this ?
Thanks All !
If ajax return is good enough, then using setDatasource api call should be your friend.
success: function (lst) {
var grid = $("#Grid").data("kendoGrid");
var dataSource = new kendo.data.DataSource({
data: lst });
grid.setDataSource(dataSource);
}
EDIT: using read (read is just wrapper over $.ajax)
Hope you have configured your grid like:
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Read(read => read.Action("Error_Search", "Error", new { ParaSearch = []}))
)
Then, wire up some event from where ParaSearch is originating and use read call as:
<script>
function someEvent(e) {
var requestData = { ParaSearch: arrObject };
grid.dataSource.read(requestData);
}
</script>

Error - No Transport , while trying to create an entity using json

//Prepare ‘Account’ object and call create function
function createAccount() {
var new_nit = new Object();
// Set text field
new_nit.Name = "Maddy";
createRecord(new_nit, "new_nitSet", createAccountCompleted, null);
}
// This callback method executes on succesful account creation
function createAccountCompleted(data, textStatus, XmlHttpRequest) {
var nit = data;
alert("Account created; Id: ");
}
// This function creates record by making OData call
function createRecord(entityObject, odataSetName, successCallback, errorCallback) {
//Parse the entity object into JSON
var jsonEntity = window.JSON.stringify(entityObject);
// Get Server URL
var serverUrl = Xrm.Page.context.getServerUrl();
//The OData end-point
var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
//Asynchronous AJAX function to Create a CRM record using OData
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: serverUrl + ODATA_ENDPOINT + "/" + odataSetName,
data: jsonEntity,
beforeSend: function (XMLHttpRequest) {
//Specifying this header ensures that the results will be returned as JSON.
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function (data, textStatus, XmlHttpRequest) {
if (successCallback) {
successCallback(data.d, textStatus, XmlHttpRequest);
}
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
if (errorCallback)
errorCallback(XmlHttpRequest, textStatus, errorThrown);
else
alert("Error on the creation of record; Error – "+errorThrown);
}
});
}
I'm using above code to create a entity called nit. I have json2 and jQuery js files in web resource. When i run this code on button click, i'm getting error as No Transport. when i searched , i got to know that this error is because of cross site scripting. How to enable cross site scripting or how to get rid of this error.
function createAccount() {
var gid = Xrm.Page.getAttribute("new_syllabus").getValue();
var stamail = new Object();
stamail.new_name = "Maddy";
stamail.new_gid = gid;
var myurl = "http://" + window.location.host + "/" + Xrm.Page.context.getOrgUniqueName();
//alert(gid);
// alert(Xrm.Page.data.entity.getId());
var jsoEntity = JSON.stringify(stamail);
var createRecordReq = new XMLHttpRequest();
var ODataPath = myurl + "/XRMServices/2011/OrganizationData.svc";
createRecordReq.open("POST", ODataPath + "/new_nitSet", false);
createRecordReq.setRequestHeader("Accept", "application/json");
createRecordReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
// createRecordReq.onreadystatechange = function () { requestCallBack(this); };
createRecordReq.send(jsoEntity);
var newRecord = JSON.parse(createRecordReq.responseText).d;
}
Instead of using ajax i used above code. Its working fine.

Resources