javascript alert parsererror

Topics related to client-side programming language.
Post questions and answers about JavaScript, Ajax, or jQuery codes and scripts.
mlucicom
Posts:37

javascript alert parsererror

hello! I have this page: elitservice.dk/contact-01.php
When i press submit button i get an alert() with "parsererror".
i test php code and work fine

Code: Select all

	<?php
require('header.php'); 
?><!-- Header /- -->
	
	<main>
		<!-- Page Banner -->
		<div class="page-banner container-fluid">
			<!-- Container -->
			<div class="container">
				<div class="banner-content">
					<h3>Kontakt</h3>
					<ol class="breadcrumb">
						<li><a href="index.php" title="Home">Home</a></li>							
						<li class="active">Kontakt</li>
					</ol>
				</div>
			</div><!-- Container /- -->
		</div><!-- Page Banner /- -->
		
		<!-- Contact Us 1 -->
		<div class="contact-us-1 container-fluid no-padding">
			<!-- Container -->
			<div class="container">
				<!-- Section Header -->
				<div class="section-header">
					<h3>Skriv til os</h3>
				</div><!-- Section Header /- -->
				<form action="contact_form.php" method="post">
					<div class="col-md-4 col-sm-4 col-xs-12 form-group">
						<input type="text" name="nume" class="form-control" id="input_name" placeholder="Dit navn" required/>
					</div>
						<div class="col-md-4 col-sm-4 col-xs-12 form-group">
									<select class="form-control"  name="tip">
<option value="Privat">Privat</option>
<option value="Erherv">Erherv</option>
</select>
					</div>
									<div class="col-md-4 col-sm-4 col-xs-12 form-group">
						<input type="text" name="oras" class="form-control" id="input_email" placeholder="By" required/>
					</div>
					<div class="col-md-4 col-sm-4 col-xs-12 form-group">
						<input type="text"  placeholder="Telefon" id="input_subject" class="form-control" name="telefon"/>
					</div>
									<div class="col-md-4 col-sm-4 col-xs-12 form-group">
						<input type="text" name="email" class="form-control" id="input_email" placeholder="Email" required/>
					</div>
					<div class="col-md-4 col-sm-4 col-xs-12 form-group">
						<input type="text" placeholder="Emne" id="input_subject" class="form-control" name="subiect"/>
					</div>
				
		
					<div class="form-group col-md-12 col-sm-12 col-xs-12">
						<textarea placeholder="Eventuel kommentar" id="textarea_message" name="descriere" rows="5" class="form-control"></textarea>
					</div>
						<div>
					
					<br/>
					<br>

					<div class="form-group">
					
						<input type="submit" value=" Submit " id="btn_submit" name="submit"/>
					</div>
					
				</form>
				<?php 
$servername = "localhost";
$username = "website_app";
$password = "";
$dbname = "website_app";

// Create connection

$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

if(isset($_POST['submit']))
{
    // get values form input text and number
    // mysql query to insert data
$nume = $_POST['nume'];
$tip = $_POST['tip'];
$oras = $_POST['oras'];
$telefon = $_POST['telefon'];
$email = $_POST['email'];
$subiect = $_POST['subiect'];
$descriere = $_POST['descriere'];
  
$sql = "INSERT INTO contact (nume, tip, oras,telefon,email,subiect,descriere)
VALUES ('$nume', '$tip','$oras' ,'$telefon' ,'$email','$subiect','$descriere')";

if ($conn->query($sql) === TRUE) {
 
echo 'ok';

} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
}
?>
				<div class="contact-detail">
					<div class="col-md-4 col-sm-6 col-xs-6">
						<div class="contact-content">
							<i class="fa fa-phone"></i>
							<h5>Ring til os:</h5>
							<p><a href="tel:+ 53 35 19 79 " title="Phone" class="phone">53 35 19 79 </a></p>
						
						</div>
					</div>
					<div class="col-md-4 col-sm-6 col-xs-6">
						<div class="contact-content">
							<i class="fa fa-paper-plane-o"></i>
							<h5>Kontakt os: </h5>
							<p><a href="mailto:info@Cleaningcsb.com" title="info@Cleaningcsb.com">kontakt@elitservice.dk</a></p>
							
						</div>
					</div>
					<div class="col-md-4 col-sm-6 col-xs-6">
						<div class="contact-content">
							<i class="fa fa-home"></i>
							<h5>Address</h5>
							<p>ElitService ApS,Lærkelunden 5</p>
							<p>7120 Vejle Øst,CVR-nr: 38353039</p>
						</div>
					</div>
				</div>
			</div><!-- Container /- -->

			<!-- Map Section -->
			<div class="map container-fluid no-padding">
				<div class="map-canvas" id="map-canvas-contact" data-lat="55.747702" data-lng="9.639178" data-string="ElitService ApS,Lærkelunden" data-zoom="12"></div>
			</div><!--  Map Section /- -->
		</div><!-- Contact Us 1 -->
	</main>
	
	<!-- Footer Main -->
	<?php
require('layout-footer.php'); 
?>
have you any ideea ?

Admin Posts:805
hello,
The problem is not in that code, but in some javascript /jquery script in that page.
The reason why this parserror message occurs is that when you simply return a string or another value fro server, it is not really Json, so the parser fails when parsing it.
You can try to remove the: dataType: "json" property in the $.ajax() code, it will not try to parse it as Json.
- Or, you can look on the net for: " alert parsererror ", you'll find aricles with some good suggestions related to that error.

mlucicom Posts:37
From wich file it's necessary to remove this AJAX function?

Admin Posts:805
Maybe from "functions.js", or ask the one who made the js scrips used in that page.

Similar Topics