javascript - success message not appearing after ajax form submitted -


i have prepared 1 html form backed jquery , php. form giving correct out put in php when form submitted, not showing success message & not getting fields empty. code given below:

   function sendcontact() {         event.preventdefault();          var valid;         valid = validatecontact();         if (valid) {             jquery.ajax({                 // input submisssion though ajax                 url: "xxxx.php",                 data: 'username=' + $("#username").val() + '&useremail=' + $("#useremail").val() + '&subject=' + $("#subject").val() + '&content=' + $(content).val(),                 type: "post",                 success: function (data) {                     // thankyou message on sucessful submission.                     $("#mail-status").html(data);                     $('#mail-status').show();                      // clear form.                     $('#username').val('');                     $('#useremail').val('');                     $('#content').val('');                 },                 error: function () {                 }             });         }     }      //error checking     function validatecontact() {         var valid = true;         $(".inputbox").css('background-color', '');         $(".info").html('');          if (!$("#username").val()) {             $("#username-info").html("(required)");             $("#username").css('background-color', '#ffffdf');             valid = false;         }         if (!$("#useremail").val()) {             $("#useremail-info").html("(required)");             $("#useremail").css('background-color', '#ffffdf');             valid = false;         }         if (!$("#useremail").val().match(/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/)) {             $("#useremail-info").html("(invalid)");             $("#useremail").css('background-color', '#ffffdf');             valid = false;         }         if (!$("#content").val()) {             $("#content-info").html("(required)");             $("#content").css('background-color', '#ffffdf');             valid = false;         }          return valid;     } 

the ajax library used is: https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript html code is:

<div id="frmcontact"> <div id="mail-status" style="display: none;">thanking you.</div>          <label style="padding-top:20px;">name</label><span id="username-info" class="info"></span><br/>         <input type="text" name="username" id="username" class="inputbox"><br>          <label>email</label><span id="useremail-info" class="info"></span><br/>         <input type="text" name="useremail" id="useremail" class="inputbox"><br/>          <label>content</label><span id="content-info" class="info"></span><br/>         <textarea name="content" id="content" class="inputbox" cols="25" rows="6"></textarea><br/>          <button name="submit" class="btnaction" onclick="sendcontact();">send</button> </div>     

i have checked no of sites & googled correct code not find?. 1 spot correct 1 please?

your error

xmlhttprequest cannot load xxxx.php. no 'access-control-allow-origin' header present on requested resource.

is saying in config file have not information saying cors (cross origins) request must enable cors on platform... see here: http://enable-cors.org/server.html , choose platform (tomcat...apache...)

also check browser support cors here: http://enable-cors.org/client.html


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -