w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
nonce token after ajax response and hash problems using ajax jquery type json
To change hash function, if only '+' is the problem you may keep a check while creating the string, next_char = Randomly-created-char; if(next_char == '+'){ //do nothing } else{ hash .= next_char; } Here is how the html and php files should be like. The ajax call is shown in the .html file. .php that loads your form for the first time. <!DOCTYPE html> <html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#check").click(function(){ $("#keyvalue").text($("#key").val()); }); $("#submit").click(function(){ var text = $("#text").val(); var key = $("#key").val(); $.ajax({ url: 'trial.php',

Categories : PHP

Create JSON from 2 associated Datamapper models
I have found solution for my problem. Here it is: # create new structure to store merged result Task_entry = Struct.new(:date, :amount, :pname) # array to get results from database all_task_items = Array.new # run through result and fill the array with required data Task.all.each do |task| task_item = Task_entry.new(task.date, task.amount, task.project.name) all_task_items << task_item end all_task_items.to_json # generate json It works for me well. Hope it can be helpful.

Categories : Ruby

Unflattening view data to JSON with Mule DataMapper
I do realize that you've asked for a DataMapper solution. In case you want an alternate solution, the following uses MEL only: <expression-component><![CDATA[ payload = [ 'PersonId': payload[0].PersonId, 'CommonProp': payload[0].CommonProp, 'DataForPerson': (['Prop1': $.Prop1, 'Prop2': $.Prop2] in payload) ]; ]]></expression-component> <json:object-to-json-transformer />

Categories : Json

Is it possible to transform a settings table with unique names into a json hash object in postgresql?
This should work in postgres-9.3. (untested, since I don't have 9.3 available here yet) DROP SCHEMA tmp CASCADE; CREATE SCHEMA tmp ; SET search_path=tmp; CREATE table pipo (name varchar NOT NULL PRIMARY KEY , value varchar); INSERT INTO pipo (name, value ) VALUES ('memory' , '10Mb'), ('disk' , '1Gb'), ('video' , '10Mpix/sec'), ('sound' , '100dB'); SELECT row_to_json( ROW(p.name,p.value) ) FROM pipo p ;

Categories : Json

i am not getting json response, instead getting json object.. how to fix it
$.getJSON doesn't return the JSON. It is asynchronous. Calling return in the callback won't change this. Instead, use this: var JsonHandler = function(callback){ return { json : function(url){ return $.getJSON(url, callback); } } }; (function ($) { var path = "js/data.json"; var getJson = new JsonHandler(function(data){console.log(data)}); getJson.json(path); })(jQuery);

Categories : Jquery

get JSON object from a HTTP response
There is a JSONObject constructor to turn a String into a JSONObject: http://developer.android.com/reference/org/json/JSONObject.html#JSONObject(java.lang.String)

Categories : Java

CodeIgniter/DataMapper: reuse object
Answer can be found here (Codeigniter/Datamapper forum): http://ellislab.com/forums/viewthread/149388/P915/#1054666

Categories : PHP

Updating Object property in DataMapper
After looking through docs and finding this outdated thread I believe I've found the solution. You can mark attributes as dirty by changing the persistence_state of a DataMapper::Resource instance. DirtyState = DataMapper::Resource::PersistenceState::Dirty quantity_property = ProductQuantity.properties[:quantity] old_quantity = prod_quantity1.quantity prod_quantity1.quantity.value = 500 dirty_state = DataMapper::Resource::PersistenceState::Dirty.new(prod_quantity1) dirty_state.original_attributes[quantity_property] = old_quantity prod_quantity1.persistence_state = dirty_state expect(prod_quantity1.persistence_state.is_a? DirtyState).to eql(true) expect(prod_quantity1.dirty?).to eql(true) prod_quantity1.save expect(prod_quantity1.dirty?).to eql(false) Basically we create a DataMapper::R

Categories : Misc

Play 2 - Can't return Json object in Response
I think the problem is that the Ok() method cannot figure out the Student needs to be transformed to json, as the arguments to Ok() may vary. You may return an Ok(Json.toJson(xs)) You may explicitly point the desired type: Ok(xs: JsValue) And be sure all implicits are in scope

Categories : Scala

How to set JSON data in node.js response object?
Could be because of async nature of callback, try this - function (error, resp, body) { indexresponseBody = JSON.stringify(JSON.parse(body).message); res.writeHead(200, {'content-type':'text/html'}); console.log("JSON returned from REST "+indexresponseBody); res.write(indexresponseBody); res.end(); }

Categories : Node Js

I can't get JSON object from response to getJSON ( jQuery )
i also noticed that your not using the key that is in your json output. $.getJSON('http://172.25.10.99/list2.php', function(data) { $('#responseParagraph').append("<p>"+data.file.filename+"</p>"); });

Categories : PHP

PHP JSON : Read contact details from Yahoo JSON response Contact Object
Try this: <?php $json = '{"contacts":{"start":0,"count":5,"total":110,"contact":[{"isConnection":false,"id":16777250,"fields":[{"id":16777292,"type":"yahooid","value":"ahmed_love7353","editedBy":"OWNER","categories":[]},{"id":16777291,"type":"name","value":{"givenName":"ahmed","middleName":"","familyName":"_love","prefix":"","suffix":"","givenNameSound":"","familyNameSound":""},"editedBy":"OWNER","categories":[]}]},{"isConnection":false,"id":52,"fields":[{"id":124,"type":"email","value":"15688708283341592078@mail.orkut.com","editedBy":"OWNER","categories":[]}]},{"isConnection":false,"id":16777271,"fields":[{"id":16777343,"type":"email","value":"abcdall4u@gmail.com","editedBy":"OWNER","categories":[]}]},{"isConnection":false,"id":31,"fields":[{"id":69,"type":"yahooid","value":"supriya_9

Categories : PHP

Get Json string of response mapping object restkit v0.2.20
That isn't what RestKit is designed for so the results it provides are the mapped content and not the source response data. Which ever way you choose to do it you will likely need to process the whole JSON data to extract the part you want. To get the individual dictionary you would probably need to subclass the mapping operation and inject it into the operation processing your request. Consider why you want to get access to the JSON. most likely what you want to do can be done in some other way as part of the mapping (perhaps using the mapping metadata).

Categories : Iphone

Struts 2 - Interceptor reset the response JSON Object
There are mutliple errors in your code. Response is HttpServletResponse, you should not give that name to a JSONObject. Interceptors are NOT THREAD-SAFE, that means that you should define the JSONObject inside the method, to prevent multiple users to update it concurrently, one over the other You should use statusCode or errorCode as described in the JSON plugin documentation, by configuring it as the Error result you are returning: Use statusCode to set the status of the response: <result name="error" type="json"> <param name="statusCode">304</param> </result> And errorCode to send an error(the server might end up sending something to the client which is not the serialized JSON): <result name="error" type="json"> <param name="errorCode

Categories : Java

Request JSON to load into Javascript object. Differences in response
If you put: http://www.myserver.com/flicks.json in a browser, can you see the data? (Is the file reachable). Second guess, are you sure the files are identical(local vs server)? EDIT 1: Try this. just a slight change in order of calls. if (request) { request.onreadystatechange = function() { if (request.readyState == 4) { var testi = request.responseText; var listmovies = JSON.parse(testi); console.log(typeof testi); // THIS RETURNS STRING console.log(typeof listmovies); // THIS RETURNS OBJECT - YAY! } }; request.open("GET", "http://www.myserver.com/flicks.json", true); request.send(null); }

Categories : Javascript

How should look link the json response so that ActiveResource may generate a DateTime object from a date?
JSON will always be a string as this is how it passes data as stringyfied objects. If you want to convert it to a date/time object you will need to parse it at the server side. Time.parse should do the trick http://ruby-doc.org/stdlib-2.0/libdoc/time/rdoc/Time.html#method-c-parse

Categories : Ruby On Rails

how to parse json object into select box.. My response is not like array format? So tel me a way to do selectbox?
You have to parse the json string (split at ) and add each option to the selection list: var selectStr = selectobj.select; var options = selectStr.split('</option>'); $.each(options, function (i, option) { $('#listProduct').append($('<option>', { value: option, text : option })); });

Categories : Json

ring.middleware.json/wrap-json-params parses numbers into strings?
This could be down to the jQuery request, rather than the ring middleware. To be honest, I don't know much about jQuery, but I just came across this answer which looks like it could explain what's happening. In short, the data from your query as it stands will be encoded as strings in the URL. These will be parsed by ring into strings, not integers, as the URL encoding does not specify the type. If you want JSON encoding, you'll need to specify it explicitly. Like so: $.ajax({ type: "POST", url: 'http://localhost:9090/request', data: JSON.stringify({type: 'add-request', val1: 12, val2: 50}), contentType: 'application/json; charset=utf-8', dataType: 'json', success: function(data){ console.log(data); });

Categories : Json

How to wrap different type of object in one single wrapper object
Implementing an interface is a better pattern than inhering a super class. in that way your classes retain their one-inheritance capacity. regarding the other question about instanceOf, there is rarely a genuine need to determine the actual class of the object. you can always resort to polymorphism. put all methods that you need to invoke on the object in the interface itself. in that way you will never need to know the actual type.

Categories : Java

How to parse a JSON response when type is also coming in response
The usual way to deal with data items which could be any of a small known number of types is to use a tagged union. In Java, you'd write one something like this: // CREATE TABLE dataFromJson (type ENUM('INT', 'BOOLEAN', 'STRING'), // intval INT, boolval INT, stringval LONGTEXT); class DataItem { public enum Type { INT, BOOLEAN, STRING }; public Type m_type; public int m_int; public bool m_boolean; public String m_string; public PreparedStatement toInsertQuery(Connection conn) { PreparedStatement ps = conn.prepareStatement("INSERT INTO dataFromJson VALUES (?, ?, ?, ?)"); ps.setString(1, m_type.toString()); if (m_type==INT) ps.setInt(2, m_int); else ps.setObject(2, null); if (m_type==BOOLEAN) ps.setBoolean(3

Categories : Android

D3 JSON diagram text wrap
SVG text elements don't allow for automatic text wrapping or line breaks unfortunately. You basically have two options: Use a tspan element (see e.g. this question). Use a foreignObject element which allows you to embed divs and thus specify a width and benefit from automatic wrapping. The latter option is probably that you want. It is more powerful and easier to use. Note that it is not supported in all browsers, notably older versions of IE, though.

Categories : Json

'this' being scoped to window object when creating JS object where function is stored in a hash
You need to put jedi.module('AddColourSchemeModel') in parentheses, when creating an instance. Otherwise you code will be interpreted as: var colourModel = (new jedi.module('AddColourSchemeModel'))({ // json object containing model values }); So the right way should be: var colourModel = new (jedi.module('AddColourSchemeModel'))({ // json object containing model values });

Categories : Javascript

Cannot see the Restangular response data set in my chrome developer tools... is it bc my JSON contains nested JSON?
I'm the creator of Restangular. So, when you're doing a getList, Restangular expects to get an Array as the response. In your case, when you're getting a list and the path is availableCourses, you're returning a string (the title) which has properties. So you're creating a "special" string with properties, it's not really common, nor compatible with Restangular. If you want to get the list of all available courses, you need to return an array as the new response. So, what's the exact response from the server when you do the getList? If you giv eme that, I'll be able to help you easier on how to create this response extarctor. Also take a look to this MongoLab example :), maybe It'll help you. http://plnkr.co/edit/d6yDka?p=preview Bests!

Categories : Angularjs

Ajax json always returning error although json format in response is correct
Indeed the string <!-- 0.375s --> is breaking your code. Try to find out where it is comming from. Some steps: What layout are you using to render this? Try debug($this->layout) in your Controleler to see which on it is. This may very well be in there since I don't see you setting the layout to ajax for example. Cake has this ajax layout, which essentially is an empty layout. It should not contain anything more than echo $content_for_layout; in CakePHP 1.3. Check and be sure that your is "spitted out" UTF-8 encoded. This is a must for JSON. Try replacing your current view code with echo json_encode($response); or to keep the trilateral check: echo isset($response) ? json_encode($response) : ''; The JavaScriptHelper will to the same thing anyway. This "strange string" may very we

Categories : Ajax

how to send media file to wcf rest json service and get string return response in json format
To send a media file (or any arbitrary file, for that matter) to WCF, you need to have an operation where the only parameter in the request body is of type Stream. That means that you can have other parameters to the operation, but they need to be passed via the URI (using the UriTemplate property of the [WebInvoke] attribute) - see more information in the post at http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-receiving-arbitrary-data.aspx. In your example, you'd have something like the code below: [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "RegisterUser?emailId={EmailID}&name={Name}&mobile={Mobile}&IMEI={IMEI}", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat= WebMessageFormat.Json, ResponseFor

Categories : Android

Receving send json to server and recive json response
It may be already answered in How to decode JSON values in my Android Aplication? BUT, if you want to parse JSON Data from the App to the Webserver you may want to use the flag true. $post = json_decode(filter_input(INPUT_POST, 'data'), true); foreach ($post as $obj) { echo $obj["yourobj"]; } If you have problems parsing the data from the webserver to the app, force it to be an object by using json_encode($data, JSON_FORCE_OBJECT); if you want to parse an array use json_encode(array("data", $yourdata)); Please explain what you want and the error you get for a proper solution matching your case.

Categories : Android

Getting 411 response code while getting JSON Response
There are a few things that don't look quite right here. I would recommend trying this: httpConnection.setRequestMethod("POST"); URLEncodedPostData postData = new URLEncodedPostData("UTF-8", false); postData.append("username", user); postData.append("password", password); byte[] postDataByte = postData.getBytes(); httpConnection.setRequestProperty("Authorization", "bearer"+"ZWOu3HL4vwaOLrFAuEFqsxNQf6ka"); httpConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); httpConnection.setRequestProperty("Content-Length", String.valueOf(postDataByte.length)); OutputStream out = httpConnection.openOutputStream(); DataOutputStream dos = new DataOutputStream(out); out.write(postDataByte); out.flush(); int statusCode = httpConnection.getResponseCode();

Categories : Java

how to make json object from an element in json object with unique values in underscore js
var col = [ { "MerchantName": "Fashion and You", "BrandList": " Nike, Fila", "MerchantImage": "Fashion-You-medium.jpeg" }, { "MerchantName": "Fashion and You", "BrandList": " Levis, Fasttrack, Fila", "MerchantImage": "Fashion-You-medium.jpeg" }, { "MerchantName": "ebay", "BrandList": "Nokia,HTC,Samsung", "MerchantImage": "ebay.jpeg" }, { "MerchantName": "amazon", "BrandList": "Apple,Dell,Samsung", "MerchantImage": "amazon.jpeg" }, { "MerchantName": "amazon", "BrandList": " pepe jeans, peter england, red tape", "MerchantImage, Fila": "amazon.jpeg" } ]; var brands = []; //get unique brands _.each(col, function(i){ brands = _.union

Categories : Javascript

AngularJS: how to open a modal above a view as a response to a hash change (ngView /$routeProvider)
You might be a bit confused about how AngularJS works - and that's completely normal especially if you are used to play with jQuery for DOM manipulation. AngularJS doesn't come with any function out of the box to launch a modal window and I can see you are using Bootstrap for that. I would suggest to take a look at the AngularJS official documentation again (http://docs.angularjs.org/) and check the first examples on the homepage to get your head around it. Also make sure to visit Egghead.io (http://egghead.io/) - really good videos tutorials there. But to give you some help I put together an example here using Bootstrap and AngularJS to launch a modal window as you want. You can see it working here (http://plnkr.co/edit/fCaNjLwi4RlCw66yKRd7) Basically the $routeprovider "points" you

Categories : Javascript

Obtaining the hash of a file using the stream capabilities of crypto module (ie: without hash.update and hash.digest)
From the quoted snippet in the question: [the Hash class] It is a stream that is both readable and writable. The written data is used to compute the hash. Once the writable side of the stream is ended, use the read() method to get the computed hash digest. So what you need to hash some text is: var crypto = require('crypto'); // change to 'md5' if you want an MD5 hash var hash = crypto.createHash('sha1'); // change to 'binary' if you want a binary hash. hash.setEncoding('hex'); // the text that you want to hash hash.write('hello world'); // very important! You cannot read from the stream until you have called end() hash.end(); // and now you get the resulting hash var sha1sum = hash.read(); If you want to get the hash of a file, the best way is create a ReadStream from th

Categories : Node Js

Parsing JSON server response into JSON Array
This should be it. So you're probably trying to get JSONObject instead of String inside the results aarray. JSONObject responseObject = new JSONObject(responseString); JSONArray resultsArray = responseObject.getJSONArray("results"); for (int i=0; i<resultsArray.length(); i++) String resultString = resultsArray.getString(i);

Categories : Java

Unable to access AJAX JSON response, despite setting content type and datatype, parseJSON returns error however still 'valid' JSON
The right answer was established in the comments: On .fail, jQuery returns a jqXHR object, instead of data. The data you're looking for is in the responseText property of this object. .fail(function(jqXHR) { var json = $.parseJSON(jqXHR.responseText); console.log(json); });

Categories : Javascript

In a file/array, search for hash key, and replace it with the hash value, do this for all hash keys/values
You exhaust your file the first time through your loop using the initial $find and $replace key/value pair. There are two potential solutions: Open the file for reading during each iteration of your while loop (expensive) Move the foreach loop to the outside of the while and iterate the hash each time (less expensive) example: REPLACE: for my $line (@gtfarray) { while(my ($find, $replace) = each %hash) { if($line =~ s/$find/$replace/g) { push @newgtf, $line; next REPLACE; # skip to next iteration } } # if there was no replacement, push the old line push @newgtf, $line }

Categories : Perl

Create a empty JSON object from an existing JSON object array
You can use an object literal to store whatever you want. It is just a bag of properties (i.e. name) and values. e.g. var order = {}; Then an array literal could be used to hold the orders. e.g var orders = []; orders.push(order); But it would be just as easy to use another object literal with the id as a property. But it seems like you want some sort of validation. Perhaps something to manage the order data and handle the validation, etc. Like so: orderManager.dataStore = { _data: {}, //_redundantData = []; //could easily store in an array if id isn't unique get: function (id) { return this._data[id]; }, getAll: function () { return this._data; }, set: function (id, order) { validateOrder(order); this._data[id] = order; }, clear: function (id)

Categories : Javascript

Retrieving Clean JSON from Response::json
Your syntax is wrong. Instead of die(Response::json(array('message': 'Success', 'status': 200', 'redirect_url': ''), 200);); use die(Response::json(array('message'=> 'Success', 'status'=> 200', 'redirect_url'=> ''), 200));

Categories : Ajax

Order JSON object alphabetical and return to JSON object
write a compare function function compare(a,b) { if (a.name < b.name) return -1; if (a.name > b.name) return 1; return 0; } then sort your data var cities = {}; $.getJSON('http://mypage.com/json/cities.php', function(data){ data.sort(compare); $.each(data, function (k, vali) { cities[vali.cid] = vali.name; }); });

Categories : Jquery

JSON hash key manipulation
Each element is hash, not array; Use keys (PC, COUNT) to get value of the hash. response = [ {"PC"=>"PC087849", "COUNT"=>"72421"}, {"PC"=>"PC087302", "COUNT"=>"71546"}, {"PC"=>"PC087255", "COUNT"=>"68420"}, ] response.map { |s| {label: s['PC'], value: s['COUNT'].to_i } } # => [ # {:label=>"PC087849", :value=>72421}, # {:label=>"PC087302", :value=>71546}, # {:label=>"PC087255", :value=>68420} # ]

Categories : Ruby

What does The Response content must be a string or object implementing __toString(), "object" given. mean and why do I only get it on the remote?
Do this to see what is returned. dd(Twitter::getSearch(array('q' => $q, 'count' => 5, 'lang' => 'sv', 'result_type' => 'recent'))); You have to return View class which has __toString() method or if it's ajax request then something like Response::json($data);

Categories : Laravel

Perl hash to json conversion?
The first four lines in Mojo::JSON's SYNOPSIS will tell you. use Mojo::JSON; my $json = Mojo::JSON->new->encode( $VAR1 );

Categories : Json

hash tables in arrays ....and JSON
The depth parameter specifies how many levels of contained objects are included in the JSON representation. The default value is 2. If you specify a value 3, the json will be created successfully: $objgraph = (New-Object PSObject | Add-Member -PassThru NoteProperty jsonrpc '2.0' | Add-Member -PassThru NoteProperty method 'graph.create' | Add-Member -PassThru NoteProperty params $params | Add-Member -PassThru NoteProperty auth $session.result | Add-Member -PassThru NoteProperty id '2') | ConvertTo-Json -depth 3

Categories : Powershell



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.