addFeatures doesn't seem to be taken in my code - openlayers-3

I'm working on openlayers 3 and ExtJS 6. I have a vector who is loaded with a GeoJson. I clear it and I want to add some new features once it's cleared.
My new data are provided by a store. So this is what I want to add in my vector :
[{"type":"Feature","properties":{"SCALERANK":6,"NATSCALE":30,"LABELRANK":5,"FEATURECLA":"Populated place","NAME":"Marsabit","NAMEPAR":null,"NAMEALT":null,"DIFFASCII":0,"NAMEASCII":"Marsabit","ADM0CAP":0,"CAPALT":0,"CAPIN":null,"WORLDCITY":0,"MEGACITY":0,"SOV0NAME":"Kenya","SOV_A3":"KEN","ADM0NAME":"Kenya","ADM0_A3":"KEN","ADM1NAME":"Eastern","ISO_A2":"KE","NOTE":null,"LATITUDE":2.329999,"LONGITUDE":37.979997,"CHANGED":1,"NAMEDIFF":0,"DIFFNOTE":"Changed scale rank.","POP_MAX":16460,"POP_MIN":15361,"POP_OTHER":16460,"RANK_MAX":6,"RANK_MIN":6,"GEONAMEID":187585,"MEGANAME":null,"LS_NAME":"Marsabit","LS_MATCH":1,"CHECKME":0,"MAX_POP10":16460,"MAX_POP20":16460,"MAX_POP50":0,"MAX_POP300":0,"MAX_POP310":0,"MAX_NATSCA":20,"MIN_AREAKM":12,"MAX_AREAKM":12,"MIN_AREAMI":5,"MAX_AREAMI":5,"MIN_PERKM":17,"MAX_PERKM":17,"MIN_PERMI":10,"MAX_PERMI":10,"MIN_BBXMIN":37.975,"MAX_BBXMIN":37.975,"MIN_BBXMAX":38.033333,"MAX_BBXMAX":38.033333,"MIN_BBYMIN":2.325,"MAX_BBYMIN":2.325,"MIN_BBYMAX":2.341667,"MAX_BBYMAX":2.341667,"MEAN_BBXC":38.004167,"MEAN_BBYC":2.333333,"COMPARE":0,"GN_ASCII":"Marsabit","FEATURE_CL":"P","FEATURE_CO":"PPL","ADMIN1_COD":3,"GN_POP":15361,"ELEVATION":0,"GTOPO30":1344,"TIMEZONE":"Africa/Nairobi","GEONAMESNO":"Geonames ascii name + lat.d + long.d matching.","UN_FID":0,"UN_ADM0":null,"UN_LAT":0,"UN_LONG":0,"POP1950":0,"POP1955":0,"POP1960":0,"POP1965":0,"POP1970":0,"POP1975":0,"POP1980":0,"POP1985":0,"POP1990":0,"POP1995":0,"POP2000":0,"POP2005":0,"POP2010":0,"POP2015":0,"POP2020":0,"POP2025":0,"POP2050":0,"CITYALT":null},"geometry":{"type":"Point","coordinates":[37.979996702838946,2.329998595077768]},"NAME":"Marsabit","id":"AIS_LIVE.model.PlacesModel-13153"},{"type":"Feature","properties":{"SCALERANK":7,"NATSCALE":20,"LABELRANK":3,"FEATURECLA":"Populated place","NAME":"Marsala","NAMEPAR":null,"NAMEALT":null,"DIFFASCII":0,"NAMEASCII":"Marsala","ADM0CAP":0,"CAPALT":0,"CAPIN":null,"WORLDCITY":0,"MEGACITY":0,"SOV0NAME":"Italy","SOV_A3":"ITA","ADM0NAME":"Italy","ADM0_A3":"ITA","ADM1NAME":"Sicily","ISO_A2":"IT","NOTE":null,"LATITUDE":37.805404,"LONGITUDE":12.438662,"CHANGED":0,"NAMEDIFF":0,"DIFFNOTE":null,"POP_MAX":77784,"POP_MIN":43179,"POP_OTHER":42587,"RANK_MAX":8,"RANK_MIN":7,"GEONAMEID":2524245,"MEGANAME":null,"LS_NAME":"Marsala","LS_MATCH":1,"CHECKME":0,"MAX_POP10":43179,"MAX_POP20":43179,"MAX_POP50":0,"MAX_POP300":0,"MAX_POP310":0,"MAX_NATSCA":20,"MIN_AREAKM":19,"MAX_AREAKM":19,"MIN_AREAMI":7,"MAX_AREAMI":7,"MIN_PERKM":25,"MAX_PERKM":25,"MIN_PERMI":16,"MAX_PERMI":16,"MIN_BBXMIN":12.425,"MAX_BBXMIN":12.425,"MIN_BBXMAX":12.491667,"MAX_BBXMAX":12.491667,"MIN_BBYMIN":37.766667,"MAX_BBYMIN":37.766667,"MIN_BBYMAX":37.816667,"MAX_BBYMAX":37.816667,"MEAN_BBXC":12.458631,"MEAN_BBYC":37.794643,"COMPARE":0,"GN_ASCII":"Marsala","FEATURE_CL":"P","FEATURE_CO":"PPL","ADMIN1_COD":15,"GN_POP":77784,"ELEVATION":0,"GTOPO30":7,"TIMEZONE":"Europe/Rome","GEONAMESNO":"Geonames ascii name + lat.d + long.d matching.","UN_FID":0,"UN_ADM0":null,"UN_LAT":0,"UN_LONG":0,"POP1950":0,"POP1955":0,"POP1960":0,"POP1965":0,"POP1970":0,"POP1975":0,"POP1980":0,"POP1985":0,"POP1990":0,"POP1995":0,"POP2000":0,"POP2005":0,"POP2010":0,"POP2015":0,"POP2020":0,"POP2025":0,"POP2050":0,"CITYALT":null},"geometry":{"type":"Point","coordinates":[12.43866166041903,37.805404275558374]},"NAME":"Marsala","id":"AIS_LIVE.model.PlacesModel-10722"},{"type":"Feature","properties":{"SCALERANK":4,"NATSCALE":50,"LABELRANK":3,"FEATURECLA":"Admin-1 region capital","NAME":"Marseille","NAMEPAR":null,"NAMEALT":"Marseille-Aix-en-Provence","DIFFASCII":0,"NAMEASCII":"Marseille","ADM0CAP":0,"CAPALT":0,"CAPIN":null,"WORLDCITY":0,"MEGACITY":1,"SOV0NAME":"French Republic","SOV_A3":"FRA","ADM0NAME":"France","ADM0_A3":"FRA","ADM1NAME":"Provence-Alpes-C-te-d'Azur","ISO_A2":"FR","NOTE":null,"LATITUDE":43.289979,"LONGITUDE":5.37501,"CHANGED":4,"NAMEDIFF":0,"DIFFNOTE":"Changed feature class.","POP_MAX":1400000,"POP_MIN":794811,"POP_OTHER":813666,"RANK_MAX":12,"RANK_MIN":11,"GEONAMEID":2995469,"MEGANAME":"Marseille-Aix-en-Provence","LS_NAME":"Marseille","LS_MATCH":1,"CHECKME":0,"MAX_POP10":946129,"MAX_POP20":1034294,"MAX_POP50":1034294,"MAX_POP300":0,"MAX_POP310":0,"MAX_NATSCA":50,"MIN_AREAKM":285,"MAX_AREAKM":361,"MIN_AREAMI":110,"MAX_AREAMI":140,"MIN_PERKM":237,"MAX_PERKM":327,"MIN_PERMI":147,"MAX_PERMI":203,"MIN_BBXMIN":5.158333,"MAX_BBXMIN":5.183333,"MIN_BBXMAX":5.633333,"MAX_BBXMAX":5.633333,"MIN_BBYMIN":43.216667,"MAX_BBYMIN":43.216667,"MIN_BBYMAX":43.466123,"MAX_BBYMAX":43.525,"MEAN_BBXC":5.397504,"MEAN_BBYC":43.351337,"COMPARE":0,"GN_ASCII":"Marseille","FEATURE_CL":"P","FEATURE_CO":"PPLA","ADMIN1_COD":0,"GN_POP":794811,"ELEVATION":0,"GTOPO30":54,"TIMEZONE":"Europe/Paris","GEONAMESNO":"Geonames ascii name + lat.d + long.d matching.","UN_FID":187,"UN_ADM0":"France","UN_LAT":43.28,"UN_LONG":5.38,"POP1950":756,"POP1955":798,"POP1960":929,"POP1965":1069,"POP1970":1182,"POP1975":1253,"POP1980":1295,"POP1985":1307,"POP1990":1305,"POP1995":1331,"POP2000":1357,"POP2005":1386,"POP2010":1400,"POP2015":1418,"POP2020":1445,"POP2025":1469,"POP2050":1490,"CITYALT":"Marseille"},"geometry":{"type":"Point","coordinates":[5.37306427182989,43.29192492260455]},"NAME":"Marseille","id":"AIS_LIVE.model.PlacesModel-13925"}]
But if I execute: me.getData('myVector').getSource().addFeatures(myData)
I've got an error.
I also tried
var format = new ol.format.GeoJSON();
me.getData('myVector').addFeatures(format.readFeatures( myData, {
featureProjection: 'EPSG:3857'
} ) );
It gives me 0 error but I when I want to display all my features there is nothing in my vector.
How can I do?

Related

Zebra Printer - Not Printing PNG Stream *Provided my own answer*

I think I'm very close to getting this to print. However it still isn't. There is no exception thrown and it does seem to be hitting the zebra printer, but nothing. Its a long shot as I think most people are in the same position I am and know little about it. Any help anyone can give no matter how small will be welcomed, I'm losing the will to live
using (var response = request.GetResponse())
{
using (var responseStream = response.GetResponseStream())
{
using (var stream = new MemoryStream())
{
if (responseStream == null)
{
return;
}
responseStream.CopyTo(stream);
stream.Position = 0;
using (var zipout = ZipFile.Read(stream))
{
using (var ms = new MemoryStream())
{
foreach (var e in zipout.Where(e => e.FileName.Contains(".png")))
{
e.Extract(ms);
}
if (ms.Length <= 0)
{
return;
}
var binaryData = ms.ToArray();
byte[] compressedFileData;
// Compress the data using the LZ77 algorithm.
using (var outStream = new MemoryStream())
{
using (var compress = new DeflateStream(outStream, CompressionMode.Compress, true))
{
compress.Write(binaryData, 0, binaryData.Length);
compress.Flush();
compress.Close();
}
compressedFileData = outStream.ToArray();
}
// Encode the compressed data using the MIME Base64 algorithm.
var base64 = Convert.ToBase64String(compressedFileData);
// Calculate a CRC across the encoded data.
var crc = Calc(Convert.FromBase64String(base64));
// Add a unique header to differentiate the new format from the existing ASCII hexadecimal encoding.
var finalData = string.Format(":Z64:{0}:{1}", base64, crc);
var zplToSend = "~DYR:LOGO,P,P," + finalData.Length + ",," + finalData;
const string PrintImage = "^XA^FO0,0^IMR:LOGO.PNG^FS^XZ";
try
{
var client = new System.Net.Sockets.TcpClient();
client.Connect(IpAddress, Port);
var writer = new StreamWriter(client.GetStream(), Encoding.UTF8);
writer.Write(zplToSend);
writer.Flush();
writer.Write(PrintImage);
writer.Close();
client.Close();
}
catch (Exception ex)
{
// Catch Exception
}
}
}
}
}
}
private static ushort Calc(byte[] data)
{
ushort wCrc = 0;
for (var i = 0; i < data.Length; i++)
{
wCrc ^= (ushort)(data[i] << 8);
for (var j = 0; j < 8; j++)
{
if ((wCrc & 0x8000) != 0)
{
wCrc = (ushort)((wCrc << 1) ^ 0x1021);
}
else
{
wCrc <<= 1;
}
}
}
return wCrc;
}
The following code is working for me. The issue was the commands, these are very very important! Overview of the command I have used below, more can be found here
PrintImage
^XA
Start Format Description The ^XA command is used at the beginning of ZPL II code. It is the opening bracket and indicates the start of a new label format. This command is substituted with a single ASCII control character STX (control-B, hexadecimal 02). Format ^XA Comments Valid ZPL II format requires that label formats should start with the ^XA command and end with the ^XZ command.
^FO
Field Origin Description The ^FO command sets a field origin, relative to the label home (^LH) position. ^FO sets the upper-left corner of the field area by defining points along the x-axis and y-axis independent of the rotation. Format ^FOx,y,z
x = x-axis location (in dots) Accepted Values: 0 to 32000 Default
Value: 0
y = y-axis location (in dots) Accepted Values: 0 to 32000
Default Value: 0
z = justification The z parameter is only
supported in firmware versions V60.14.x, V50.14.x, or later. Accepted
Values: 0 = left justification 1 = right justification 2 = auto
justification (script dependent) Default Value: last accepted ^FW
value or ^FW default
^IM
Image Move Description The ^IM command performs a direct move of an image from storage area into the bitmap. The command is identical to the ^XG command (Recall Graphic), except there are no sizing parameters. Format ^IMd:o.x
d = location of stored object Accepted Values: R:, E:, B:, and A: Default Value: search priority
o = object name Accepted Values: 1 to 8 alphanumeric characters Default Value: if a name is not specified, UNKNOWN is used
x = extension Fixed Value: .GRF, .PNG
^FS
Field Separator Description The ^FS command denotes the end of the field definition. Alternatively, ^FS command can also be issued as a single ASCII control code SI (Control-O, hexadecimal 0F). Format ^FS
^XZ
End Format Description The ^XZ command is the ending (closing) bracket. It indicates the end of a label format. When this command is received, a label prints. This command can also be issued as a single ASCII control character ETX (Control-C, hexadecimal 03). Format ^XZ Comments Label formats must start with the ^XA command and end with the ^XZ command to be in valid ZPL II format.
zplToSend
^MN
Media Tracking Description This command specifies the media type being used and the black mark offset in dots. This bulleted list shows the types of media associated with this command:
Continuous Media – this media has no physical characteristic (such as a web, notch, perforation, black mark) to separate labels. Label length is determined by the ^LL command.
Continuous Media, variable length – same as Continuous Media, but if portions of the printed label fall outside of the defined label length, the label size will automatically be extended to contain them. This label length extension applies only to the current label. Note that ^MNV still requires the use of the ^LL command to define the initial desired label length.
Non-continuous Media – this media has some type of physical characteristic (such as web, notch, perforation, black mark) to separate the labels.
Format ^MNa,b
a = media being used Accepted Values: N = continuous media Y = non-continuous media web sensing d, e W = non-continuous media web sensing d, e M = non-continuous media mark sensing A = auto-detects the type of media during calibration d, f V = continuous media, variable length g Default Value: a value must be entered or the command is ignored
b = black mark offset in dots This sets the expected location of the media mark relative to the point of separation between documents. If set to 0, the media mark is expected to be found at the point of separation. (i.e., the perforation, cut point, etc.) All values are listed in dots. This parameter is ignored unless the a parameter is set to M. If this parameter is missing, the default value is used. Accepted Values: -80 to 283 for direct-thermal only printers -240 to 566 for 600 dpi printers -75 to 283 for KR403 printers -120 to 283 for all other printers Default Value: 0
~DY
Download Objects Description The ~DY command downloads to the printer graphic objects or fonts in any supported format. This command can be used in place of ~DG for more saving and loading options. ~DY is the preferred command to download TrueType fonts on printers with firmware later than X.13. It is faster than ~DU. The ~DY command also supports downloading wireless certificate files. Format ~DYd:f,b,x,t,w,data
Note
When using certificate files, your printer supports:
- Using Privacy Enhanced Mail (PEM) formatted certificate files.
- Using the client certificate and private key as two files, each downloaded separately.
- Using exportable PAC files for EAP-FAST.
- Zebra recommends using Linear sty
d = file location .NRD and .PAC files reside on E: in firmware versions V60.15.x, V50.15.x, or later. Accepted Values: R:, E:, B:, and A: Default Value: R:
f = file name Accepted Values: 1 to 8 alphanumeric characters Default Value: if a name is not specified, UNKNOWN is used
b = format downloaded in data field .TTE and .TTF are only supported in firmware versions V60.14.x, V50.14.x, or later. Accepted Values: A = uncompressed (ZB64, ASCII) B = uncompressed (.TTE, .TTF, binary) C = AR-compressed (used only by Zebra’s BAR-ONE® v5) P = portable network graphic (.PNG) - ZB64 encoded Default Value: a value must be specified
clearDownLabel
^ID
Description The ^ID command deletes objects, graphics, fonts, and stored formats from storage areas. Objects can be deleted selectively or in groups. This command can be used within a printing format to delete objects before saving new ones, or in a stand-alone format to delete objects.
The image name and extension support the use of the asterisk (*) as a wild card. This allows you to easily delete a selected groups of objects. Format ^IDd:o.x
d = location of stored object Accepted Values: R:, E:, B:, and A: Default Value: R:
o = object name Accepted Values: any 1 to 8 character name Default Value: if a name is not specified, UNKNOWN is used
x = extension Accepted Values: any extension conforming to Zebra conventions
Default Value: .GRF
const string PrintImage = "^XA^FO0,0,0^IME:LOGO.PNG^FS^XZ";
var zplImageData = string.Empty;
using (var response = request.GetResponse())
{
using (var responseStream = response.GetResponseStream())
{
using (var stream = new MemoryStream())
{
if (responseStream == null)
{
return;
}
responseStream.CopyTo(stream);
stream.Position = 0;
using (var zipout = ZipFile.Read(stream))
{
using (var ms = new MemoryStream())
{
foreach (var e in zipout.Where(e => e.FileName.Contains(".png")))
{
e.Extract(ms);
}
if (ms.Length <= 0)
{
return;
}
var binaryData = ms.ToArray();
foreach (var b in binaryData)
{
var hexRep = string.Format("{0:X}", b);
if (hexRep.Length == 1)
{
hexRep = "0" + hexRep;
}
zplImageData += hexRep;
}
var zplToSend = "^XA" + "^FO0,0,0" + "^MNN" + "~DYE:LOGO,P,P," + binaryData.Length + ",," + zplImageData + "^XZ";
var label = GenerateStreamFromString(zplToSend);
var client = new System.Net.Sockets.TcpClient();
client.Connect(IpAddress, Port);
label.CopyTo(client.GetStream());
label.Flush();
client.Close();
var cmd = GenerateStreamFromString(PrintImage);
var client2 = new System.Net.Sockets.TcpClient();
client2.Connect(IpAddress, Port);
cmd.CopyTo(client2.GetStream());
cmd.Flush();
client2.Close();var clearDownLabel = GenerateStreamFromString("^XA^IDR:LOGO.PNG^FS^XZ");
var client3 = new System.Net.Sockets.TcpClient();
client3.Connect(IpAddress, Port);
clearDownLabel.CopyTo(client3.GetStream());
clearDownLabel.Flush();
client3.Close();
}
}
}
}
}
}
Easy once you know how.
Zebra ZPL logo example in base64
Python3
import crcmod
import base64
crc16 = crcmod.predefined.mkCrcFun('xmodem')
s = hex(crc16(ZPL_LOGO.encode()))[2:]
print (f"crc16: {s}")
Poorly documented may I say the least

Parsing Projection WKT in OpenLayers 3

I am looking for a method (javascript) (external or internal part of ol3) that can parse a projection WKT to its proj4 text and create the projection.
<SRS>PROJCS["GDA94 / MGA zone 53",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.2572221010002,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4283"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",135],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",10000000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","28353"]]</SRS>
Above shows an example of the XML element containing the SRS.
I have found out that if I can convert this to proj4 text. Then i can add it as a projection this way:
proj4.defs("EPSG:28353", "+proj=utm +zone=53 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");
var def = proj4.defs(grid.srs);
var units = def.units;
var proj = new ol.proj.Projection({
code: grid.srs,
units: units,
axisOrientation: def.axis
});
proj.setExtent(/*...*/);
ol.proj.addProjection(proj);
var proj4Transform1 = proj4('EPSG:3857', grid.srs);
ol.proj.addCoordinateTransforms(ol.proj.get('EPSG:3857'), proj,
proj4Transform1.forward, proj4Transform1.inverse);
var proj4Transform2 = proj4('EPSG:4326', grid.srs);
ol.proj.addCoordinateTransforms(ol.proj.get('EPSG:4326'), proj,
proj4Transform2.forward, proj4Transform2.inverse);
Is it possible to find the extend of the projection in the WKT also or should I look this up also external?
proj4js supports WKT strings too. You can throw what you have (excluding the <SRS> tag) directly at proj4js, using the same syntax:
proj4.defs("EPSG:28353", "PROJCS["GDA94 / MGA zone 53",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.2572221010002,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4283"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",135],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",10000000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","28353"]]");
Once you have defined a projection using proj4.defs(), it will be immediately be available in OpenLayers 3, and all transforms will be registered. So the proj4.defs() line is all you need unless you want to set additional options, like the projection extent in your case. There are two options to do this: 1) globally:
ol.proj.get('EPSG:28353').setExtent(*/ ... */);
or 2) just for one ol.proj.Projection instance that you use to e.g. configure your ol.View:
var projection = new ol.proj.Projection({
code: 'EPSG:28353',
extent: /* ... */
});

POI in OpenLayer 3

If load points from KML file to vetor layer
var layerPOI = new ol.layer.Vector({
source: new ol.source.KML({
projection: projection,
url: 'data/KML/mydata.kml'
})
})
How can I do a complete listing of all loaded points (POIs) and loaded properties (from data/KML/mydata.kml)? I think, for example, into the table - in map view (display layer) I can is already
Thank you very much for answer
ol.source.KML has a method getFeatures() which gives you all features in your KML. Then you can use getProperties() or get() on the feature to read the properties.
(Partial) solution:
allPOIs = layerPOI.getSource().getFeatures();
// or if define a source separatly
// allPOIs = sourcePOI.getFeatures();
onePOI = allPOIs[0]; // first element in Array
propertiesOfOnePOI = onePOI.getKeys();
propertiesOfOnePOI.forEach(function (elementName, elementIndex){
console.log( "element index: " + elementIndex + " | element name: " + elementName + " | element value: " + onePOI.get(elementName) );
});
But the element GEOMTERY returns Object.
I try to getting additional information about point yet but I can not -
Also more tags from KML file - For example, point style - how to determine the displayed icon?
Please still help ;)

Getting classification result from mahout

Finally I am able to train mahout classifier , now my problem is how can i get target category for my input document.
What is the process of getting target category for my text documents ?
First, you have to vectorize the text document, RandomAccessSparseVector.
Some sample code for your reference:
Vector vector = new RandomAccessSparseVector(FEATURES);
FeatureExtractor fe = new FeatureExtractor();
HashSet<String> fs = fe.extract(text);
for (String s : fs) {
int index = dictionary.get(s);
vector.setQuick(index, frequency.get(index));
}
Then, use the Classifier.classify(Vector) to get the result.

JQUERY call to Controller Action: String Parameter truncated if containing 'space' character

I have a view that accepts 2 string parameters and 2 date values. User hits search button and they get filtered output to the screen. This all works perfectly well until a user inputs a string with a space. i.e. they can search for 'waste' but not 'waste oil'.
Interestingly, in the latter, the parameter is ok from Javascript before the call is made. But on entering the controller code it goes form being 'waste oil' on client to 'waste'. When this happens the other parameters get set to NULL crashing the system.
I've tried replacing the spaces if present with '#' character then stripping out and putting back in ' ' on the controller side. This is a messy fudge and only appears to work with one parameter.
There must be a simple explanation for this parameter data loss, any comments much appreciated
Not sure a code example is needed but here it is anyway if it help:
My controller header :
public ActionResult IndexSearch(int? page, string searchText,string searchTextSite,string StartDate,string EndDate)
{
My HTML Javascript :
function Search(sSearchText,sSite) {
sSearchText = sSearchText.toString().replace(" ", "#");
sSite = sSite.toString().replace(" ", "#");
debugger;
alert($("#AbsolutePath").val() + "Waste.mvc/IndexSearch?searchText=" + sSearchText + "&searchTextSite=" + sSite + "&StartDate=" + $('#StartDate').val() + "&EndDate=" + $('#EndDate').val());
$("#ResultsList").load($("#AbsolutePath").val() + "Waste.mvc/IndexSearch?searchText=" + sSearchText + "&searchTextSite=" + sSite + "&StartDate=" + $('#StartDate').val() + "&EndDate=" + $('#EndDate').val(),
function() {
$('#LoadingGif').empty();
});
$('#LoadingGif').empty().html('<img src="' + $("#AbsolutePath").val() + 'Content/images/ajax-loader.gif" alt="Loading image" />');
}
You are not URL encoding your parameters when sending the AJAX request because you are using string concatenations when building the url. You could use the following technique in order to have properly encoded values:
var url = $('#AbsolutePath').val() + 'Waste.mvc/IndexSearch';
var data = {
searchText: sSearchText,
searchTextSite: sSite ,
StartDate: $('#StartDate').val(),
EndDate: $('#EndDate').val()
};
$('#ResultsList').load(url, data, function() {
$('#LoadingGif').empty();
});
Now you will get correct values on the server.

Resources