JQuery successful POST php not enabled
source link: https://www.codesd.com/item/jquery-successful-post-php-not-enabled.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
JQuery successful POST php not enabled
I'm racking my brain and I can not make it work.
I am using jQuery to call a PHP page:
$.ajax({
type: "POST",
url: postUrl,
data: formData,
async : false,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: App.successfulAdd,
error: App.errorAdd
});
successfulAdd : function(result) {
alert("Success!");
},
The PHP:
echo json_encode(array('msg' => 'failed'));
Firebug show:
{"msg":"failed"}
But the successfulAdd function is not called! Any idea why?
I have changed to
$.ajax({
type: "POST",
url: postUrl,
data: formData,
async : false,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (data) {
alert("Success!");
},
error: function (data) {
alert("Error!");
}
});
But still Error! is displayed.
Update
Finally I found! Use Notepad++ and was as UTF8 encoding. Changed to UTF8 without BOM and now everything works beautifully.
Try changing to:
success: function(result) {
App.successfulAdd(result);
},
error: function(result) {
App.errorAdd(result);
}
This will evaluate the properties when the response arrives, not when you send the request. I suspect you're sending the request while you're building the App
object, and these properties haven't been assigned yet.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK