I have implemented an Ajax request on my website, and I am calling the endpoint from a webpage. It always returns 200 OK, but jQuery executes the error event.
I tried a lot of things, but I could not figure out the problem. I am adding my code below:
jQuery Code
var row = "1";
var json = "{'TwitterId':'" + row + "'}";
$.ajax({
type: 'POST',
url: 'Jqueryoperation.aspx?Operation=DeleteRow',
contentType: 'application/json; charset=utf-8',
data: json,
dataType: 'json',
cache: false,
success: AjaxSucceeded,
error: AjaxFailed
});
function AjaxSucceeded(result) {
alert("hello");
alert(result.d);
}
function AjaxFailed(result) {
alert("hello1");
alert(result.status + ' ' + result.statusText);
}
C# code for JqueryOpeartion.aspx
protected void Page_Load(object sender, EventArgs e) {
test();
}
private void test() {
Response.Write("<script language='javascript'>alert('Record Deleted');</script>");
}
I need the ("Record deleted") string after successful deletion. I am able to delete the content, but I am not getting this message. Is this correct or am I doing anything wrong? What is the correct way to solve this issue?
Добрый день. Помогите разобраться.
Есть форма
<form id="feedback">
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" id="name">
</div>
<div class="form-group">
<label>email</label>
<input type="email" class="form-control" id="email" >
</div>
<div class="form-group">
<label>theme</label>
<input type="text" class="form-control" id="theme" >
</div>
<div class="form-check">
<label>
massage
</label>
<textarea id="message" class="form-control"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
есть ajax запрос
$(document).ready(function(){
$('button').on('click', function(e){
e.preventDefault();
sendMessage();
});
function sendMessage()
{
var user_name = $('#name').val(),
user_email = $('#email').val(),
user_theme = $('#theme').val(),
user_message = $('#message').val();
$.ajax({
url: 'action.php',
type: 'POST',
dataType: 'JSON',
data: {
name: user_name,
email: user_email,
theme: user_theme,
message: user_message
},
success: function(data){
alert('done');
},
error: function(request, status, error){
var statusCode = request.status; // вот он код ответа
console.log(statusCode);
}
})
}
})
и есть файл action.php который обрабатывает ajax и должен записывать в базу
$name = $_POST['name'];
$email = $_POST['email'];
$theme = $_POST['theme'];
$message = $_POST['message'];
$db_host = "*****";
$db_user = "*****";
$db_password = "******";
$db_table = "feedback";
$db = mysql_connect($db_host,$db_user,$db_password) OR DIE("Не могу создать соединение ");
// Выборка базы
mysql_select_db("*****_db",$db);
mysql_query ("INSERT INTO feedback (name, email, theme, message,) VALUES ('$name', '$email', '$theme', '$message')");
во время выполнения ajax отрабатывает error: и в консоль выводит статус 200 и в базу ничего не записывается
Are you struggling to find a solution for drupal ajax error 200? We can help you in fixing it.
Here at Bobcares, we have seen several such Drupal errors as part of our Server Management Services for web hosts, Drupal users, and online service providers.
Today we’ll take a look at the cause for this error and see how to fix it.
What causes Drupal Ajax Error 200 to occur
Before we get into the solution part of the error, let’s first discuss more on this error message.
Many Drupal users have encountered this error in a modal window when using Panels. “An AJAX HTTP error occurred. HTTP Result Code: 200 Debugging information follows.”
In general, the Ajax error occurs when jQuery fails into its error callback handler, which will occur when the server responds with a 2xx HTTP status code.
The status code 200 indicates an OK response
This Drupal error normally occurs because of a Javascript conflict with some other module or theme.
For instance, the error appears as below.
How we fix Drupal Ajax Error 200
Till now we have discussed the error and its causes. Now let’s see the solution part of this error.
Here are the different solutions that our Support Engineers provide to our customers to get rid of this error.
1. Try to remove the Drupal for Firebug addon.
2. Try to disable the Firebug.
3. Flush the theme’s cache.
4. Uninstall Jquery UI and Jquery Update modules.
5. Try to disable the Theme Developer module.
6. Try to remove the Twitter Profile module.
These above ways helped our customers in fixing the Drupal Ajax 200 error.
[Need any further assistance in fixing Drupal errors? – We’re available to help you]
Conclusion
In short, this drupal error occurs due to a Javascript conflict with some other module or theme. Today, we saw how our Support Engineers assist our customers In fixing this error.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
GET STARTED
var google_conversion_label = «owonCMyG5nEQ0aD71QM»;
- Remove From My Forums
-
Question
-
User549085165 posted
Hi, I'm doing a simple ajax example but for some reason it keeps fireing 'error' yet the status returned is 200. Any reasons 'success' is not fired with the simple message? Do I need to reference the json library or is this included with jquery? Default.aspx : <script type="text/javascript" src="scripts/jquery-1.4.3.min.js"></script> <script type="text/javascript"> function getMessage() { $.ajax({ type: "POST", url: "Default.aspx/sayHello", contentType: "application/json; charset=utf-8", data: "{}", dataType: "json", success: function(response) { alert(response.d); }, error: function(response) { alert(response.status); } }); } </script> <title>Calling a page method with jQuery</title> </head> <body> <form id="form1" runat="server"> <input type="button" value="get message" onclick="getMessage()" /> </form> Default.aspx.cs:using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Web.Services; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } [WebMethod()] public static string sayHello() { return "hello "; } }
Answers
-
User1020195037 posted
It was probably an issue with caching that was cleared up with the reboot. Depending on your browser settings, the ajax url could have been cached and returned an old error even though the code had been changed. I have had this happen in the past. One
hacky method around this is to append an unused querystring parameter that will be different for each request. To do this I will add the current date/time as a querystring parameter. This will force the browser and the server to pull up a new
version of the page regardless of the caching settings.-
Marked as answer by
Thursday, October 7, 2021 12:00 AM
-
Marked as answer by
I am receiving the following Ajax error when on any Views page. The Drupal logs (/admin/reports/dblog) don’t have any corresponding events. I’ve tried disabling all custom and view related modules and adjusting jQuery versions with no success.
I’m running Drupal 7.57-dev and Views 7.x-3.18
I know there are several other questions about this error but their solutions are specific or not relevant to this specific response text.
How do I begin drupal shooting this error?
asked Oct 22, 2017 at 9:32
The <?php tag at the beginning of the ResponseText indicates that there is a stray <?php in the markup, this was being caused by a syntax error in a completely unrelated template.
After template syntax error was fixed the Ajax Http 200 error pop-up went away.
answered Oct 24, 2017 at 13:39
SamSam
5557 silver badges26 bronze badges
I have the same problem with BOM, I just :
grep -rl $’xEFxBBxBF’ .
And correct it with phpstorm :
File > Remove BOM
answered Jan 31, 2018 at 7:57
PinchPinch
111 bronze badge


