How to post a json object to controller using dojo ajax? - dojo

I am trying to search details when i give a category or task in drop down.
The name of the particular form using dijit/form/Form that does the searching is searchForm.
I have converted the entries into json and trying to post these details using dojo ajax. When I try this,I am not getting the dropdown and I am getting a text box instead.
dojo.xhrPost({
url: "/filter.q4",
postData: dojo.formToJson("searchForm");
headers : {
"Content-Type" : "application/json,charset=utf-8"
},
load: function(response,ioargs) {
alert('success');
},
error : function(response,ioargs) {
alert('error');
}
});
How can I solve this problem?

Your obvious error is here:
postData: dojo.formToJson("searchForm");
Note the trailing semicolon? That's your problem. You want a comma, instead:
postData: dojo.formToJson("searchForm"),
This should get you past your immediate issue.

Related

Is it possible to pass data via the post method to magnific popup when ajax loading content?

I'm using magnific popup and ajax loading content into it and passing values to the ajax content by appending a query string to the url, which works fine except in IE7 (and probably IE8 as well). The reason is very likely the length of the query string, because it works when I shorten it.
So my question is, is it possible to pass it via some sort of data setting and make it use POST instead of GET. Or does it already use post and I just need to use the right method.
This is what I have:
$.magnificPopup.open({
tLoading:"",
modal:false,
type:'ajax',
alignTop:true,
items:{src:urlContainingVeryLongQueryString},
callbacks:
{
ajaxContentAdded:function()
{
...
My test url is 906 characters long in total (well within IE7's 2000ish limit).
ajax.settings option http://dimsemenov.com/plugins/magnific-popup/documentation.html#ajax_type is passed to jQuery.ajax method http://api.jquery.com/jQuery.ajax/#jQuery-ajax-settings , e.g.:
$.magnificPopup.open({
tLoading:"",
modal:false,
type:'ajax',
alignTop:true,
items:{src:'http://example.com/ajax'},
ajax: {
settings: {
type: 'POST',
data: {
foo: 'bar'
}
}
}
});

KendoUI pagination throws exception and doesn't show page information

I'm trying to get a KendoUI grid working with server side paging. So far I've managed to get the grid reading data from the remote datasource and correctly sending paging/filtering information to an MVC controller action
This is working fine, however, I don't see the paging controls for the grid at all.
I've tried adding pageable: true to the setup of the grid, and although this does display the pager control, it doesn't show any pages/totals and throws a JS object does not support this property or method when I try and change the page using the next/prev page buttons. The method it's looking for is 'slice' - I'm going to have a look at the non-minified kendo src but in the meantime I thought I'd post here
The action looks like this:
public ActionResult _Index(int? pageSize, int? skip, string filter = "")
{
// Code that gets the data
var data = ... (some Linq->Entities queries)
var total = ... (total count of all the entities)
return Json(new { total, data });
}
I'm correctly returning the total, and I've checked the JSON and it matches what I'm expecting (and what the grid should be expecting)
The grid setup is this:
$(document).ready(function () {
var grid = $("#itemList").kendoGrid({
toolbar: kendo.template($("#template").html()),
columns: ["Manufacturer", "Model", "Price", "Tags"],
dataSource: {
transport: {
read: {
url: "catalogadmin/_index",
dataType: "json",
type: "POST",
data: {
filter: ""
}
},
},
schema: {
data: "data", // records are returned in the "data" field of the response
total: "total" // total number of records is in the "total" field of the response
},
pageSize: 2,
serverPaging: true
},
pageable: true
});
I set the pageSize to 2 to test paging (as I only have 4 items in the DB at the mo)
JSON is:
{"total":4,"data":[{"Id":6,"Manufacturer":"hello","Model":";lmqw;lemwqe","Price":4.00,"ShortDescription":"world","Tags":[],"Used":false}]}
I don't think that's the issue though - it seems like you need to set pageable: true to get paging working - but I don't think the paging even works with client side data, I'm just going to check now
Edit: I've checked and client-side paging doesn't work either. I get an 'Unable to get property toLowerCase of undefined or null reference' when trying to page. The pager looks like the server side page, no data, no page numbers, no totals.
I'm thinking Kendo isn't quite registered right - I've got the very latest version (just downloaded it now) but no cigar...
Sorted - not sure why but when I installed KendoUI using Teleriks 'convert to Kendo UI project' it registered both the kendo.all.min.js file and also the mvc/dataviz ones.
I removed the extra script references and it's all working now!

how to get pjscrape to print out current url in a file?

I am using pjscrape to scrape content from dynamic pages generated by a site. Please see code below.
I cant figure out what I need to do to get it to print out the url of the scraped page in the json variables dumped to a file. I have tried various ways of doing it - including document.url etc ( see lines 3-6 that are commented out in code below ). However I cant figure out how to get the urlFound variable to get the right value. Of course, the answer might be dead simple but its eluding me. Any other way of doing this? Help!
var scraper = function() {
return {
//urlFound:$(window.location.href),
//urlFound: $(this).window.location.href,
//urlFound: _pjs.toFullUrl($(this).attr('href')),
//urlFound: _pjs.toFullUrl($(this).URL),
// Heck - how to print out the url being scraped???
name: $('h1').text(),
marin: _pjs.getText($("script:contains('marin')"))
}
};
pjs.config({
// options: 'stdout', 'file' (set in config.logFile) or 'none'
log: 'stdout',
// options: 'json' or 'csv'
format: 'json',
// options: 'stdout' or 'file' (set in config.outFile)
writer: 'file',
outFile: 'scrape_output.json'
});
pjs.addSuite({
url: 'http://www.mophie.com/index.html',
moreUrls: function() {
return _pjs.getAnchorUrls('li a');
},
scraper: scraper
});
Don't need jquery for your selector on window.location.href. Not sure how to get access to the internal url of pjscraper, but changing your code to this works:
var scraper = function() {
return {
urlFound: window.location.href,
name: $('h1').text(),
marin: _pjs.getText($("script:contains('marin')"))
}
};
Or you can just use document.URL...save that as a variable and then write it to a file using How to read and write into file using JavaScript

Need multiple language support in Ajax file upload

I'm uploading a file using jQuery through Ajax. I'm submitting some form elements also, which needs to be [utf-8] multiple language support. When submitting, it becomes junk values. How do I solve this issue?
Help me. Thanks in advance.
Firefox am using.
$.ajaxFileUpload(
{
url:action,
workflow:workflow,
arguments:argumentList,
secureuri:false,
fileElementId:filename,
dataType: 'html',
success: function(data, status) {
//alert(data);
var id = $("#linkdata",data).find("label").html();
var $htmldata = "<tr id='"+id+"'><td><label ><input id='' name='' value='' type='checkbox'>Tenant</label>"
+"</td><td><label>"+title_e+"</label></td><td><label>"+title_a+"</label></td><td><label>"+desc_e+"</label></td>"
+"<td><label>"+desc_a+"</label></td><label class='fileuid '>"+file +"</label></td></tr>";
+"<input id='test' name='fileuidList' value='"+id+"' type='hidden'>"
//$("#fileuidList").val($("#fileuidList").val()+","+id) +
$("#id_tenant").parent().append( $htmldata);
},
error: function (data, status, e)
{
alert("error"+e);
}
}
)
the form is submitting as "multipart" if i remove that the value are coming correctly but file wont be coming. help me out
i did a mistake with mysql configuration. now its working fine

WCF table data to ExtJS Store

I've set up a WCF service to provide table data in JSON:
{
"d":{
"__type":"ExtJsDataResults:#MyProject.WebServices",
"rows":[
["TitleA","1.98","English"],
["TitleB","1.98","Spanish"],
["TitleC","1.98","Korean"]
],
"totalcount":10
}
}
How to read this into an ExtJS Store? I need a JsonStore to begin with, but then an ArrayReader-type type interpret the row data. Something like this:
var itemStore = new Ext.data.JsonStore({
proxy: new Ext.data.HttpProxy({
url: "../WebServices/ItemsService.svc/getData",
method: "GET"
}),
root: "d.rows",
totalProperty: "d.totalcount",
fields: ['Book Title', 'Unit Price', 'Language'],
reader: new Ext.data.ArrayReader({},
Ext.data.Record.create([
{name:'Book Title'},
{name:'Unit Price'},
{name:'Language'}
])
)
});
Of course, this doesn't work. When bound to a DataGrid w/ a paging toolbar, it displays blank rows, but the correct number of them, and the paging toolbar values are all correct.
Any ideas?
FIXED. Changed to a regular Store and added the "root" and "totalProperty" values to the config object of the ArrayReader.
cf. this Sencha Forum thread
I was also facing this problem but got through with this solution -
http://dotnetkeeda.blogspot.in/2013/11/working-with-sencha-extjs-and-wcf.html
Nice and important tips thanks to the author.