double controller value in URL call by ajax - javascript

I got a strange problem. while i run my VS and click specific button on browser, an ajax function fired and shows error. After debugging i found the URL is showing error. the error is::
POST http://localhost:4942/Employee/Employee/AllEmployees 404 (Not Found)
The problem is, for some reason the "/Employee" controller is coming two times.
my ajax call is:
function allEmployeeFunc() {
$.ajax({
type: "POST",
url: "Employee/AllEmployees",
//data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
// context:"" ,
error: function (msg) {
alert("something is wrong");
},
success: function (data) {
}
});
}
Here the URL clearly showing only one /Employee. so whats the problem?? can anyone help please??

Try to add a slash to the URL
url: "/Employee/AllEmployees"

I guess you are using too much in url; I can see "/Employee/Employee/AllEmployees". Employee twice. Rather try
url: "AllEmployees"
I guess that should do. Assuming that you have annotation [HttpPost] in place to hit AllEmployees function.

Related

Open file upload dialog after Ajax post success

I have functionality in which it is required to open file upload dialog after Ajax call success event.
What I tried:
I tried applying below simple code in ajax success: and complete: event but it is not working.
$.ajax({
url: url,
type: 'GET',
dataType: 'json',
data: { id: eoid },
contentType: 'application/json; charset=utf-8',
success: function (data) {
// some logic
$("#fileupload").click();
}
});
What is problem:
If I put simple button and try to execute above code, it is working fine and opening dialog - but it is not working in case of ajax post afterwards.
Any guesses or am I missing something?
Thank you.
The problem is at dataType: 'json' . You are loading html with your ajax request so you should change it to dataType: 'html' else in any other format it will not be considered success. Or you can delete this property as stated in Jquery doc that Jquery does default: Intelligent Guess (xml, json, script, or html).

Post form using javascript

I have problem in submit file. The submit coding is working on my wampserver.
But When i load it to server. Post method is not working. Following are the code.
var datastring = $("#aprovel_form").serialize();
$.ajax({
type: "POST",
url: "db/suppler_add_to_job_db.php",
data: datastring,
dataType: "json",
success: function(data) {
//var obj = jQuery.parseJSON(data); if the dataType is not specified as json uncomment this
// do what ever you want with the server response
alert(data);
window.location.replace("http://www.tesiy.com/abcmail/rasasaree_system_part_2/pages/?page=supplier/add_suppler_from_begin");
},
error: function(){
alert('error handing here');
}
})
I get the alert('error handing here'). Please help me.
Sorry Guys. Finally i find the problem. The suppler_add_to_job_db.php file was not complete uploaded. It was damaged. That's why the post method was working. Anyway thanks for your helps friends.

RESTful request in ajax and react

good day, im trying to consume a web service in react, but im having problems with the ajax function, i'm not sure if is working my code is this:
prox= {"email":email, "password": password};
//tag comment
$.ajax({
type: 'POST',
url: (web service url),
data: JSON.stringify(prox),
contentType: "application/json; charset=utf-8",
crossDomain: true,
dataType: 'json',
success: function(data) {
this.setState({success: true, result: data});
alert("success");
this.setState({prueba: 'success'});
}.bind(this),
error: function() {
this.setState({failure: true});
alert("failure");
this.setState({prueba: 'failure'});
}.bind(this)
});
but i dont have any alert, when i click the button only re-render the form, the function handdle submit works, i try it putting a confirm() in the space where the //tag comment is and the confirm pop up, but the alerts dont, i think that i have an error in the function or something, thank's for the help.
I didn't run the script but just looking at it I imagine the problem could be your bind(this)
this.setState to me should be an error “is not a function” as this is not the react object. To get an alert try placing the alert as the first state.
To be sure just look at your browser console.
It looks like its working for the most part. I threw it into a JSBin and nothing seems to be out of the ordinary.
http://jsbin.com/rulaguxote/1/edit?html,js,output
I kept your JSX mostly the same, and added a few things in the component to help you visualize its state. Click the button to send a fake ajax request. Depending on the state, it will either send back an HTTP status of 200 or 400 (success or failure). This way, you can see how the success() and error() functions behave.
Another thing to note: If you are concerned that your .bind(this) is the reason your code is not working, you can specify the context like this:
$.ajax({
type : 'POST',
url : '/test',
data : JSON.stringify(prox),
contentType : "application/json; charset=utf-8",
context : this, //use this instead of .bind
success : function (data) {
this.setState({success : true, failure : false});
alert("success");
},
error : function () {
this.setState({failure : true, success : false});
alert("failure");
}
});
Let me know if you have any questions.
Doing some extensive research i see that my real problem whas the same origin policy, now im working fine in the localhost version of the project, thank you.

Ajax cross domain POST in IE8 and IE9

I am trying to make a ajax cross domain POST in IE9 and IE8 to a rest endpoint that resets a password and am not having any luck. The ajax call I am trying to make is as follows:
$.ajax({
type: 'POST',
crossDomain: true,
url: postUrl,
contentType: 'application/json; charset=utf-8',
data:{ "userid":uid, "email":email, "password":password },
dataType: 'jsonp',
success: function (data) {
console.log(data);
},
error: function (status){
console.log(status);
}
});
I am also making sure to include the following before the POST call:
$.support.cors = true;
Everytime I make the call it goes into the error function. It says the status is success however when I try to login with the new password it is not working which means it wasnt a success. The following is the response that I output to the log:
[object Object]{readyState: 4, status: 200, statusText: "success"}
Also note that I am calling the jQuery.XDomainRequest.js by MoonScript. That several other stack overflow answers say to do. And my jquery version is 1.11.3
Can someone please provide me some direction on this.

jQuery AJAX call to .NET code-behind won't return

adAsText(file);
$.ajax({
url: "WebForm1.aspx/OnSubmit",
rn "abcd";
}
it is a success and all the contents of the file prints as an alert, but I can't get it to return. It there something wrong with the content/data type?
Your Code is not clear.
I think you should clear it as much as possible. The Error I see is that you are not calling the server side function anywhere. Then how you hope to be having returned data. First Call the function by passing a string value to it.
I think this is your problem, if not, please clarify more.
Try changing dataType to json. Even though it should infer, it's better to be explicit.
$.ajax({
url: "WebForm1.aspx/OnSubmit",
type: "POST",
data: file,
dataType: "json",
contentType: "plain/text; charset=utf-8",
processData: false,
error: function (msg) {
console.log(msg.d);
alert("error");
},
success: function (msg) {
console.log(msg.d);
alert(file);
}
});

Categories

Resources