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.
Related
I am trying to send some data to my server using an AJAX Post call. However, whenever I run the function containing the ajax call I get a server error. Here is my AJAX call (I am trying to send a string and put it inside json for the purposes of this call):
function sendFileName(){
data_to_send={"name": scriptName};
data_to_send=JSON.stringify(data_to_send);
$.ajax({
url: '/filename',
type: 'POST',
dataType: 'json',
data: data_to_send,
error: function(resp){
console.log("Oh no...");
console.log(scriptName);
console.log(resp);
},
success: function(resp){
console.log('Sent file name!');
console.log(resp);
}
});
}
When I log the scriptName I get it in the console, so the data exists. I'm assuming the issue has to do with the way in which I'm sending it?
Here is the server-side code as well, where when I log the req it shows up as undefined:
app.post("/filename", function(req,res) {
file = req.body.name;
console.log(file);
});
Would really appreciate any help I can get with this!
I'm able to dump value of the variable message in console .
But im not able to send it off in POST Request.
AJAX call:
chat.throwmsg = function(message) {
if ($.trim(message).length != 0) {
console.log(message);
$.ajax({
url: 'ajax/chat.php',
type: 'post',
data: { method: 'throw', message: message} ,
success: function(data) {
chat.fetchmsgs();
$('textarea#entry').val('');
}
});
}
}
This maybe due to wrong syntax, but I've tried both single and double quotes, and combination as well .
With a wild assumption, you are not having any error messages in developer console and chat.php has a post handler forthese parameters
Since your data is JSON, please change the code as this way and have a try..
var temp={ method: 'throw', message: message};
var param=JSON.stringify(temp);
$.ajax({
url: 'ajax/chat.php',
type: 'post',
data: param ,
dataType: "json",
success: function(data) {
chat.fetchmsgs();
$('textarea#entry').val('');
}
});
after reviewing the code I could not find any issues that restrict the data to be sent along with ajax request,if you are having any syntax errors you should have been warned prior the request initialization, however I recommend you to check the request header in the network tab of browser console and see your sending data along with the request if it's there you probably need to check the code of getting the post data in your server-side implementations
I want to consume a API Rest aplication using JQuery Ajax. this is the code that I have:
var res=$('#myForm').attr('action');
console.log(res);
$.ajax({
url: res,
success: function (data) {
alert('success!!');
},
dataType: 'html'
});
The console.log sentence is printing the url correctly, I just copied and pasted it into the browser and its correct, it's something like this:
http://localhost/myproject/public/2
But then, the request gives a 404 error, and the URL that is requesting is this one:
http://localhost/localhost/myproject/public/2
So, why it's attaching another localhost line to the url? I just don't understand!
All you need is to get the part after localhost. For this, please use split method.
var res=$('#myForm').attr('action');
console.log(res);
$.ajax({
url: res.split('localhost')[1],
success: function (data) {
alert('success!!');
},
dataType: 'html'
});
I am not able to get data that is in Bengali language from server using ajax. The data from server is getting replaced by something I don't know. But if I normally set the data means not using ajax, data is getting displayed properly. My code is:
<meta content="html/text" charset="UTF-8"> in .jsp file
$.ajax({
url: "",
data: "a=a",
contentType: "charset=utf-8",
method: "get",
success:function(){
},
failure:function(){
}
});
I have taken reference from UTF8 encoding not working when using ajax, but even this did not work.
The error is in the ajax statement config.
contentType="charset=utf-8",
Here, you should use : instead of =.
See the error highlighted in the code below.
$.ajax({
url: "YOUR URL HERE?myparam1=value1¶m2=value2",
data: "a=a",
contentType: "charset=utf-8",
// ^
method: "GET",
success: function(resp) {},
failure: function(err) {}
});
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.