json.parse and ajax was working ok. until when i set my database online - json

The json.parse method was working fine . but when i host database in web hosting . it takes me
JSON.parse: unexpected character at line 1 column 1 of the JSON data
this is my code :
function getListProduitsByIdcat(id)
{
$j.get("/java 2015 v0/admin/code%20php/code_produits.php?idca="+id,function(data,status)
{
for(var i=0;i<data.length;i++)
list=[];
list=JSON.parse(data);
names=[];
for(var j=0;j<list.length;j++)
names.push(list[j].nom);
$j("#produit").autocomplete({
source: names,
change: function(event,ui)
{
if(!ui.item){
//http://api.jqueryui.com/autocomplete/#event-change -
// The item selected from the menu, if any. Otherwise the property is null
//so clear the item for force selection
$j("#produit").val("");
$j("#produit").attr("placeholder","n'exist pas ");
}
},
focus: function (event, ui) {
return false;
}
});
}
);
}

The error is explicit, Json in data isn't a valid Json. Can you print the data content ?
But I see you didn't check the status, so you don't know if the get method have success or not.
The first for do anything ?
BTW, You have space in your url it's a mistake ?
/java 2015 v0/admin/code%20php/code_produits.php?idca=

Related

Why is the "Add Note" button giving an exception and printing null on the console?

I am trying to add a note using Add Note Button but it is throwing an exception. I handled the error using try...catch block but the note written in Add Note Button is not added and printing null on console.
JSBin for my project:
This piece:
if(notes =='')
{
notesObj = [];
}
else{
notesObj = JSON.parse(notes);
}
is the problem. If there's nothing in the local storage, notes will be null, which means notesObj == '' will be false, and the code will break. You need to change the test so it detects null (and other falsy values) as such:
if(!notes)
{
notesObj = [];
}
else{
notesObj = JSON.parse(notes);
}
There's another problem. This line:
localStorage.setItem('notes', JSON.stringify(notes));
makes no sense. You're setting the item notes in the local storage as the converted json of the notes variable, which is already a JSON string, so it'll fail horribly. What you really want to do is stringify the notesObj variable, which is the array with the actual notes. Change that line to:
localStorage.setItem('notes', JSON.stringify(notesObj));
And that's it. Make those changes and your code will work.

NetSuite Online HTML Form - link to list within NetSuite

I have an online html form that uses a select field to choose a record from an existing record list (postcodes specifically) which then auto-populates other fields on the form with the rest of the address. This all works fine except that the dropdown list on the form only goes up so far. I need to know if this a limit on the html dropdown or how many records can be passed to the list in the first place?
Also, ideally, it would be great if there was a way to do it via auto-complete so as you start typing the postcode, it only shows those beginning with said characters - is this possible?
I would set up a custom html template for your online form. You can then hide your standard field and include a custom text input field. Attach an event handler to the custom field to do the lookup via a suitelet. If the auto-population is already working then your event handler can update the hidden standard field once a match is made so Netsuite's built-in sourcing works.
A sample suitelet. The get... functions return anything that can be JSON used by your page.
function service(request, response) {
var obj = {
success: true
};
try {
var step = request.getParameter('step') || 'start';
switch (step) {
case 'start':
obj.choices = getChoiceRoots(request.getParameter('itemid'), request.getParameter('treeName'));
break;
case 'other':
obj.choices = getChoiceChildren(request.getParameterValues('choiceIds[]') || request.getParameterValues('choiceIds'));
break;
default:
throw "Unexpected step: " + step;
}
} catch (e) {
obj.success = false;
obj.message = e.message || e.toString();
nlapiLogExecution('ERROR', "error getting choices", (e.message || e.toString()) + "<br> " + request.getURL() + (e.getStackTrace ? "<br> " + e.getStackTrace().join("<br> ") : ''));
}
_sendJS(request, response, obj);
function _sendJS(request, response, respObject) {
response.setContentType('JAVASCRIPT'); //'application/json');
var callbackFcn = request.getParameter("jsoncallback") || request.getParameter('callback');
if (callbackFcn) {
response.writeLine(callbackFcn + "(" + JSON.stringify(respObject) + ");");
} else response.writeLine(JSON.stringify(respObject));
}
}
Then on your page you'd have a script that uses the suitelet. (the suitelet needs to be available without login and the audience needs to be All.
The code on your custom template or associated script file would look something like:
//suiteletURL will look like https://forms.netsuite.com. RegExp makes that root relative to the domain you are on.
//This is not actually necessary when using JSONP but it can be useful in some circumstances so I left it in this example.
$.getJSON(suiteletURL.replace(new RegExp(".*://[^/]+/"), '/')+"&"+$.param(params) +"&callback=?",
function(d, txtStatus,xhr){
if(d.errorCode){
if(fail){
fail(xhr, txtStatus, null);
}else{
showMessage("#appMessage", d.errorMessage || ("Request Failed with code: "+xhr.responseJSON.errorCode));
}
}else{
success(d, txtStatus, xhr); // your custom success handler. d is already an object; no parsing necessary.
}
});

Getting Current Data from KendoUI TreeView

I'm using a kendo UI tree with a remote data source from a JSON file.
I have a button on the tree page which gets the current data of the tree,sends it through a POST to a server and the server saves the current data to the JSON file so as the next time I reload the page,the changes I made will be kept.That's what I want to happen.
So I know the current data of the tree is in:
$("#treeview").data("kendoTreeView").dataSource.data()
Which means the data changes real time in there for example when someone drag and drops a node of the tree.
My problem starts when this data doesn't seem to change when I drag and drop nodes inside the tree,and only changes when I drag and drop a node on the root level of the tree and even then it doesn't do it correcly as the node should be moved in there as well but instead the node gets copied,leaving the past node in the tree as well...
For Example I have this tree:
If I make a drag and drop change like this:
And I send the data,save it and reload the change isn't made at all!
PS:Even when I view the current data after the change before sending it,I see that there is no change on the data at all even though I did a change visualy with a drag and drop.So it doesn't have to do with the sending,saving and the server.
On the other hand,if I make a change like this:
I can see in the current data that the moved node is added in the end of the data indeed but it is not deleted from it's initial position within the data!So if i send the current data to the server,save it and then refresh I get the result:
The code for viewing and sending the data is:
function sendData() {
var req = createRequest();
var putUrl = "rest/hello/treeData";
req.open("post", putUrl, true);
req.setRequestHeader("Content-type","application/json");
var dsdata = $("#treeview").data("kendoTreeView").dataSource.data();
alert(JSON.stringify(dsdata));
req.send(JSON.stringify(dsdata));
req.onreadystatechange = function() {
if (req.readyState != 4) {
return;
}
if (req.status != 200) {
alert("Error: " + req.status);
return;
}
alert("Sent Data Status: " + req.responseText);
}
}
Is this a Bug or am I doing something wrong?Has anyone been able to see the current data changing correctly on every drag and drop?
First and most important you have to use the latest version of KendoUI (Kendo UI Beta v2012.3.1024) still in beta but is where they have solved many problems.
Then, when you create the kendoTreeView you have to say something like:
tree = $("#treeview").kendoTreeView({
dataSource :kendo.observableHierarchy(data),
dragAndDrop:true
}).data("kendoTreeView");
Here the important is not using directly data array but wrapping it with kendo.observableHierarchy.
Then you will have the data updated with the result of drag & drops.
For me in addition to OnaBai answer I had to use the sync function on the save method. I am using Type Script.
this.treeData = new kendo.data.HierarchicalDataSource({
data: kendo.observableHierarchy([]),//Thanks OnaBai
schema: {
model: {
id: "MenuItemId",
children: "MenuItemChildren",
hasChildren: (e) => {
//this removes arrow next to items that do not have children.
return e.MenuItemChildren && e.MenuItemChildren.length > 0;
}
}
}
});
public save() {
this.treeData.sync().done(() => {
console.log("sync data");
var myType = this.treeData.view();
this.$http.post("/api/TreeViewPicker", myType)
.then((response) => {
});
});
}

problems displaying my array via JSON object

Hi I am having a problems displaying my array via JSON object. I passed two variables to PHP which returns an array. I then wish to loop through the array and append the result to a div
The PHP works fine as I have tested this before adding the JQuery. When I use google chrome to inspect the console, I dump out data which displays as [] not an object, is this correct?
the contents of the array do not have a key, only a collection of list items with an image path for example
<li><img src="'.$image_path.'"</li>
I encode the array back to the listener,
echo json_encode($result);
code for JQuery
$.post('Look_Controller.php', {look: look, account: account}, function(data) {
$.each(data, function(i, item) {
$('#carousel-ul').empty();
content = item;
$(content).appendTo('#carousel-ul');
});
}, "json");
How do I append each individual result to the div (#carousel-ul)?,
I have also tried
content = item.this;
content = (this).item;
content = $(this).item;
I am not sure if it because the console.log(data) displays [] instead of object?
Hope someone can advise!
Thanks
What happen when you try this ?
$.post('Look_Controller.php', {look: look, account: account}, function(data) {
$('#carousel-ul').empty();
console.log(data);
$.each(data, function(i, item) {
console.log(item);
content = item;
// If "carousel-ul" is a <ul> tag uncomment the next line
// content = $('<li/>').html(content);
$(content).appendTo('#carousel-ul');
});
}, "json");
[] is an empty array. If that's what's being shown you have no data.
So it's probably not coming back from the server. Check the Network tab in the Chrome debugger and see what your response looks like.

multiple tinyMce instances not working in chrome

As with the title in Chrome (v.4.1) multiple tinyMce (v2.08) instances do not work. To be exact the first two instances are ok, the others not, and chrome gives this error:
Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1
Has this happened before?
Unfortunately I can't show you any code because it's for an admin area, I just need some clue for the moment.
Yes, as user XP1 noted, at this link you can find resolution for a comprimed TinyMCE source:
http://my.opera.com/XP1/blog/2011/07/21/tinymce-javascript-error-in-opera-getrangeat-index-size-err
But if you want to work with original uncomprimed source (it's just a bit easier), here is the solution:
Look for code "setRng : function(r) {" (without quotes) and exchange the whole function with:
setRng : function(r) {
var s, t = this;
if (!t.tridentSel) {
s = t.getSel();
if (s) // this block fixed according to TinyMCE JavaScript error in Opera (getRangeAt, INDEX_SIZE_ERR); http://my.opera.com/XP1/blog/2011/07/21/tinymce-javascript-error-in-opera-getrangeat-index-size-err
{
if(s.anchorNode === null && s.focusNode === null)
{
t.explicitRange = r;
try {
s.removeAllRanges();
} catch (ex) {
// IE9 might throw errors here don't know why (NOW WE KNOW WHY DAMMIT!)
}
s.addRange(r);
}
if (s.rangeCount > 0)
t.selectedRange = s.getRangeAt(0);
}
} else {
// Is W3C Range
if (r.cloneRange) {
t.tridentSel.addRange(r);
return;
}
// Is IE specific range
try {
r.select();
} catch (ex) {
// Needed for some odd IE bug #1843306
}
}
},
ONE NOTE: please make sure variables match. I am not sure how it is between different TinyMCE versions BUT the variables are not the same between comprimed and src mutations of the script file.
Take Care and God Speed