Can't get Result of Ajax Call
I'm sending a request to a php file from a form using Ajax. And I want to
receive a result from this php file.
Here's my code :
<script type="text/javascript">
jQuery(document).ready(function($){
$('#devis_gratuit').submit(function(e){
e.preventDefault();
$.getJSON(
'mail.php', {
prestation: $('.prestation-input').val(),
heures: $('.heures-input').val(),
nom: $('.nom-input').val(),
ville: $('.ville-input').val(),
prenom: $('.prenom-type').val(),
code_postal: $('.code_postal-input').val(),
tel: $('.tel-input').val(),
email: $('.email-status').val()},
function(data){
alert("A"); //Doesn't work
$('#status').hide();
$('#status').html('')
.append('<b>Paramètre en majuscule</b> :
'+data.response+'<br/>');
$('#status').fadeIn();
}
);
});
});
</script>
and my php code mail.php:
if(isset($_GET['prestation'])
&& isset($_GET['heures'])
&& isset($_GET['nom'])
&& isset($_GET['prenom'])
&& isset($_GET['ville'])
&& isset($_GET['code_postal'])
&& isset($_GET['tel'])
&& isset($_GET['email']))
{
$response = "Ok";
die($response); //Doesn't work
}
else {
$response = "Ko";
die($response); //Doesn't work
}
$return = array('response' => $response);
header('Content-type: application/json');
But it looks like it's not getting on the PHP file and I see on firebug
that the request is Sent successfully. Any help please ? Thank you.
Buttermore
Sunday, 1 September 2013
ViewModel and JSON
ViewModel and JSON
Problem Background :
I have a ViewModel called VM_a. Its content will be serialized into JSON
string on form submission, and then saved into DB - 1 form for each
record.
When I choose to display all records of VM_a, I will deserialize the
records of VM_a, populate them into List and then show them in JQGrid.
Below are the snippets which I've used to deserialize, and the actual
ViewModel.
ViewModel :
public class VM_a
{
public string var_1 { get; set; }
public string var_2 { get; set; }
public string var_3 { get; set; }
public string var_4 { get; set; }
}
Deserialization :
public static T Deserialize<T>(object json)
{
if (typeof(T).IsAssignableFrom(typeof(T)))
{
object res = JsonConvert.DeserializeObject(json.ToString(), new
JsonSerializerSettings()
{
ContractResolver = resolver,
TypeNameHandling = TypeNameHandling.All
});
return (T)res;
}
throw new NotImplementedException("Type is not assignable.");
}
Usage of deserialization :
VM_a instanceVM = Project.Shared.JSONHelper.Deserialize<VM_a>(json_string);
Problem 1 :
I want to display the data in JQGrid and have its column dynamically
generated.
By dyamically generated, I mean each form (or VM) will have their
corresponding set of fields that will be displayed, which is stored in DB.
Example :
VM_a which has 4 fields, will be displayed in just 3 fields : var_1, 3,
and 4.
Another VM, called VM_b which has 7 fields, will be displayed in just 5
fields : 1,3,4,5,7.
If this is hardcoded, then I can simply VM_a.var_1.ToString();
How can I achieve this? Is it System.Reflection ?
Problem 2 :
If I want to store in DB which VM that I should use for deserializing, how
can I do that from code?
Example :
I clicked a link to a form, and then get its type - let's say "Form A".
Then I looked into DB and know that for "Form A", I should deserialize it
using "VM_a".
However, since that information is retrieved as a String, how can I use it
on deserialization as a Type ?
Problem Background :
I have a ViewModel called VM_a. Its content will be serialized into JSON
string on form submission, and then saved into DB - 1 form for each
record.
When I choose to display all records of VM_a, I will deserialize the
records of VM_a, populate them into List and then show them in JQGrid.
Below are the snippets which I've used to deserialize, and the actual
ViewModel.
ViewModel :
public class VM_a
{
public string var_1 { get; set; }
public string var_2 { get; set; }
public string var_3 { get; set; }
public string var_4 { get; set; }
}
Deserialization :
public static T Deserialize<T>(object json)
{
if (typeof(T).IsAssignableFrom(typeof(T)))
{
object res = JsonConvert.DeserializeObject(json.ToString(), new
JsonSerializerSettings()
{
ContractResolver = resolver,
TypeNameHandling = TypeNameHandling.All
});
return (T)res;
}
throw new NotImplementedException("Type is not assignable.");
}
Usage of deserialization :
VM_a instanceVM = Project.Shared.JSONHelper.Deserialize<VM_a>(json_string);
Problem 1 :
I want to display the data in JQGrid and have its column dynamically
generated.
By dyamically generated, I mean each form (or VM) will have their
corresponding set of fields that will be displayed, which is stored in DB.
Example :
VM_a which has 4 fields, will be displayed in just 3 fields : var_1, 3,
and 4.
Another VM, called VM_b which has 7 fields, will be displayed in just 5
fields : 1,3,4,5,7.
If this is hardcoded, then I can simply VM_a.var_1.ToString();
How can I achieve this? Is it System.Reflection ?
Problem 2 :
If I want to store in DB which VM that I should use for deserializing, how
can I do that from code?
Example :
I clicked a link to a form, and then get its type - let's say "Form A".
Then I looked into DB and know that for "Form A", I should deserialize it
using "VM_a".
However, since that information is retrieved as a String, how can I use it
on deserialization as a Type ?
ext.NET accordion is not working correctly (MVC)
ext.NET accordion is not working correctly (MVC)
Could someone please point me in the right direction here, I've spent
hours on this!
I am trying to create a West region Container that contains an image fixed
in height, with an accordion control below that takes up the rest of the
vertical space.
Every time I try this, the accordion control does not work properly. It
renders with the top node expanded, and all the other nodes jammed up
together (not at the bottom). Also, when you start using the accordion, it
just seems to stop reacting to user clicks completely. My suspicion is the
way I am laying out the control (I am new to ext.NET).
I have created a class that supplies to the view the ext.NET control. The
function that returns the West region returns an ext.NET Container.
ext.Image image = new ext.Image
{
ImageUrl = "~/resources/images/welcome-screens.png",
Height = 200,
};
ext.Container outer = new ext.Container
{
Border = true,
Region = ext.Region.West,
Width = 200,
Split = true
};
outer.Items.Add(image);
ext.Panel acc = new ext.Panel
{
Title = "ACCORDION PANEL",
Layout = ext.LayoutType.Accordion.ToString()
};
acc.Items.Add(new ext.Panel { Title = "TEST1", Items = { new
ext.Panel { Title = "a" }, new ext.Panel { Title = "b" } }
});
acc.Items.Add(new ext.Panel { Title = "TEST2", Items = { new
ext.Panel { Title = "c" } }});
acc.Items.Add(new ext.Panel { Title = "TEST3", Items = { new
ext.Panel { Title = "d" } }});
acc.Items.Add(new ext.Panel { Title = "TEST4", Items = { new
ext.Panel { Title = "e" } }});
acc.Items.Add(new ext.Panel { Title = "TEST5", Items = { new
ext.Panel { Title = "f" } } });
outer.Items.Add(acc);
Any pointers or advice would be really welcome. Thanks.
Could someone please point me in the right direction here, I've spent
hours on this!
I am trying to create a West region Container that contains an image fixed
in height, with an accordion control below that takes up the rest of the
vertical space.
Every time I try this, the accordion control does not work properly. It
renders with the top node expanded, and all the other nodes jammed up
together (not at the bottom). Also, when you start using the accordion, it
just seems to stop reacting to user clicks completely. My suspicion is the
way I am laying out the control (I am new to ext.NET).
I have created a class that supplies to the view the ext.NET control. The
function that returns the West region returns an ext.NET Container.
ext.Image image = new ext.Image
{
ImageUrl = "~/resources/images/welcome-screens.png",
Height = 200,
};
ext.Container outer = new ext.Container
{
Border = true,
Region = ext.Region.West,
Width = 200,
Split = true
};
outer.Items.Add(image);
ext.Panel acc = new ext.Panel
{
Title = "ACCORDION PANEL",
Layout = ext.LayoutType.Accordion.ToString()
};
acc.Items.Add(new ext.Panel { Title = "TEST1", Items = { new
ext.Panel { Title = "a" }, new ext.Panel { Title = "b" } }
});
acc.Items.Add(new ext.Panel { Title = "TEST2", Items = { new
ext.Panel { Title = "c" } }});
acc.Items.Add(new ext.Panel { Title = "TEST3", Items = { new
ext.Panel { Title = "d" } }});
acc.Items.Add(new ext.Panel { Title = "TEST4", Items = { new
ext.Panel { Title = "e" } }});
acc.Items.Add(new ext.Panel { Title = "TEST5", Items = { new
ext.Panel { Title = "f" } } });
outer.Items.Add(acc);
Any pointers or advice would be really welcome. Thanks.
Saturday, 31 August 2013
Using ConcurrentHashMap efficiently?
Using ConcurrentHashMap efficiently?
I have a Android Application whose core component is a
HashMap<String,float[]>. The System is having high concurrency. e.g here
are the following three situations I have which occur frequently and they
are highly overlapping in nature
Iterate through all the keys in the hashmap and do some operation on its
value(read only operations).
Add new key,value pairs in the Hashmap.
Remove Certain keys from the Hashmap.
I do all these operations in different threads and thus am using a
ConcurrentHashMap since some inconsistency in retrievals doesnt matter.
e.g While iterating the map,if new entries are added then it doesnt matter
to not read in those new values immediately as I ensure that next time
they are read .
Also while removing the entries I am recreating the iterator everytime to
avoid "ConcurrentModificationException"
Suppose , there is a following hashmap(i.e ConcurrentHashmap)
ConcurrentHashMap<String,float[]> test=new ConcurrentHashMap<String,
float[]>(200);
Now for Retrieval I do the following
Iterator<String> reader=test.keySet().iterator();
while(reader.hasNext())
{
String s=reader.next();
float[] temp=test.get(s);
//do some operation with float[] temp here(read only
operation)
}
and for removal I do the following
boolean temp = true;
while (temp) {
for (String key : test.keySet()) {
temp = false;
if (key.equals("abc")) {
test.remove(key);
temp = true;
break;
}
}
}
and when inserting in new values I simply do
test.put("temp value", new float[10]);
I am not sure if its a very efficient utilisation. Also it does matter not
to read in removed values(however I need efficiency ,and since the
iterator is again created during the function call,its guaranteed that in
the next time I don't get the removed values)so that much inconsistency
can be tolerated?
Could someone please tell me an efficient way to do it?
I have a Android Application whose core component is a
HashMap<String,float[]>. The System is having high concurrency. e.g here
are the following three situations I have which occur frequently and they
are highly overlapping in nature
Iterate through all the keys in the hashmap and do some operation on its
value(read only operations).
Add new key,value pairs in the Hashmap.
Remove Certain keys from the Hashmap.
I do all these operations in different threads and thus am using a
ConcurrentHashMap since some inconsistency in retrievals doesnt matter.
e.g While iterating the map,if new entries are added then it doesnt matter
to not read in those new values immediately as I ensure that next time
they are read .
Also while removing the entries I am recreating the iterator everytime to
avoid "ConcurrentModificationException"
Suppose , there is a following hashmap(i.e ConcurrentHashmap)
ConcurrentHashMap<String,float[]> test=new ConcurrentHashMap<String,
float[]>(200);
Now for Retrieval I do the following
Iterator<String> reader=test.keySet().iterator();
while(reader.hasNext())
{
String s=reader.next();
float[] temp=test.get(s);
//do some operation with float[] temp here(read only
operation)
}
and for removal I do the following
boolean temp = true;
while (temp) {
for (String key : test.keySet()) {
temp = false;
if (key.equals("abc")) {
test.remove(key);
temp = true;
break;
}
}
}
and when inserting in new values I simply do
test.put("temp value", new float[10]);
I am not sure if its a very efficient utilisation. Also it does matter not
to read in removed values(however I need efficiency ,and since the
iterator is again created during the function call,its guaranteed that in
the next time I don't get the removed values)so that much inconsistency
can be tolerated?
Could someone please tell me an efficient way to do it?
validating untrusted HTML input do I have to process each input?
validating untrusted HTML input do I have to process each input?
For Cross-site_scripting vulnerabilities
1)is it a good idea to validate and escape each and every one of the user
inputs
2)is using strip_tags good enough and what's the benefit of htmlpurifier
over it?
For Cross-site_scripting vulnerabilities
1)is it a good idea to validate and escape each and every one of the user
inputs
2)is using strip_tags good enough and what's the benefit of htmlpurifier
over it?
Express + Angular routing causing infinite loop + crash
Express + Angular routing causing infinite loop + crash
I'm work on a Node app using Express as well as Angular. I'm using Angular
for routing and have my routes setup like so:
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/', {
templateUrl: '/partials/main'
//controller: 'IndexController'
}).when('/discover', {
templateUrl: '/partials/discover'
}).when('/user/home', { //HERES THE PROBLEM CHILD!!!!!
templateUrl: '/partials/user/home'
}).otherwise({
redirectTo: '/'
});
}]).config(['$locationProvider', function ($locationProvider) {
$locationProvider.html5Mode(true);
}]);
Now, whenever I try and call /user/home -- The page goes into an infinite
loop and keeps reloading the controller. I can see in the node console
that the page was called from partials/user/home which definitely contains
a Jade file. I've checked other posts, most of them are solved with ass
the / in the beginning of the partials path, that didn't help here. The
page loads fine if I transfer home.jade into the /partials directory with
no sub directory. Any ideas?
I'm work on a Node app using Express as well as Angular. I'm using Angular
for routing and have my routes setup like so:
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/', {
templateUrl: '/partials/main'
//controller: 'IndexController'
}).when('/discover', {
templateUrl: '/partials/discover'
}).when('/user/home', { //HERES THE PROBLEM CHILD!!!!!
templateUrl: '/partials/user/home'
}).otherwise({
redirectTo: '/'
});
}]).config(['$locationProvider', function ($locationProvider) {
$locationProvider.html5Mode(true);
}]);
Now, whenever I try and call /user/home -- The page goes into an infinite
loop and keeps reloading the controller. I can see in the node console
that the page was called from partials/user/home which definitely contains
a Jade file. I've checked other posts, most of them are solved with ass
the / in the beginning of the partials path, that didn't help here. The
page loads fine if I transfer home.jade into the /partials directory with
no sub directory. Any ideas?
Facebook login OK but cannot connect to app
Facebook login OK but cannot connect to app
I am using Facebook JavaScript SDK.
When I click the Facebook Share button on my web page, the Facebook Login
window pops up. I typed in the username and password, logged in, and the
message "User cancelled login or did not fully authorize" showed up. I did
log in successfully, but somehow the permissions requested are not
authorized.
When I clicked the Facebook Share button again, the message "User is
logged in to Facebook, but not connected to app" showed up.
The Facebook app is created successfully with App ID & App Secret. I have
also entered the domain name under App Domains and my site under Website
with Facebook Login.
I do not know what went wrong.
Any help is appreciated!
This is the Facebook Login window, but it does not ask the user to
authorize permissions.
The code is as follows:
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'myAppId',
channelUrl : '/www.mydomain.com/channel.html',
oauth : true,
cookie : true,
status : false
});
};
function facebookLogin() {
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome!');
} else {
console.log('User cancelled login or not fully
authorized');
}
},
{scope:'email,publish_actions'});
}
function getLoginStatus() {
FB.getLoginStatus(function(response) {
if (response.status == 'connected') {
// Do something
}
return response.status;
});
}
(function(d, s, id) {
var js, fjs = d.getElementByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
.
.
.
</body>
This is the button code:
$('#fb-button').click(function() {
// Check whether login is successful.
var responseStatus = getLoginStatus();
if (responseStatus === 'connected') {
console.log("User logged in to Facebook successfully");
} else if (responseStatus === 'not_authorized') {
console.log("User is logged in to Facebook, but not connected to
app");
} else {
console.log("User is not logged in to Facebook");
facebookLogin();
}
}
I am using Facebook JavaScript SDK.
When I click the Facebook Share button on my web page, the Facebook Login
window pops up. I typed in the username and password, logged in, and the
message "User cancelled login or did not fully authorize" showed up. I did
log in successfully, but somehow the permissions requested are not
authorized.
When I clicked the Facebook Share button again, the message "User is
logged in to Facebook, but not connected to app" showed up.
The Facebook app is created successfully with App ID & App Secret. I have
also entered the domain name under App Domains and my site under Website
with Facebook Login.
I do not know what went wrong.
Any help is appreciated!
This is the Facebook Login window, but it does not ask the user to
authorize permissions.
The code is as follows:
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'myAppId',
channelUrl : '/www.mydomain.com/channel.html',
oauth : true,
cookie : true,
status : false
});
};
function facebookLogin() {
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome!');
} else {
console.log('User cancelled login or not fully
authorized');
}
},
{scope:'email,publish_actions'});
}
function getLoginStatus() {
FB.getLoginStatus(function(response) {
if (response.status == 'connected') {
// Do something
}
return response.status;
});
}
(function(d, s, id) {
var js, fjs = d.getElementByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
.
.
.
</body>
This is the button code:
$('#fb-button').click(function() {
// Check whether login is successful.
var responseStatus = getLoginStatus();
if (responseStatus === 'connected') {
console.log("User logged in to Facebook successfully");
} else if (responseStatus === 'not_authorized') {
console.log("User is logged in to Facebook, but not connected to
app");
} else {
console.log("User is not logged in to Facebook");
facebookLogin();
}
}
Subscribe to:
Comments (Atom)