troubleshooting Question

Ajax Call to Identical External Script Doesn't Fire

Avatar of Paul Konstanski
Paul KonstanskiFlag for United States of America asked on
2 Comments1 Solution242 ViewsLast Modified:
I have a script that works perfectly when I run it from my local machine.  But when I try to run it with a call to an external server it returns a failure. I know the script actually arrives at my remote machine because I see it's arrival in the logs, but it doesn't properly send back the success notification.

The application is a webpage that has a simple "contact us" link with two inbound fields - name and email.  The standard html page makes a call to a file called "contact_me.js" which contains this code:

$(function() {
        preventSubmit: true,
        submitError: function($form, event, errors) {
            // additional error messages or events
        submitSuccess: function($form, event) {
            event.preventDefault(); // prevent default submit behaviour
            // get values from FORM
	    var rmturl = "././mail/contact_me.php";
	    // var rmturl = "";
            var name = $("input#name").val();
            var email = $("input#email").val();
            var phone = $("input#phone").val();
            var message = $("textarea#message").val();
            var firstName = name; // For Success/Failure Message
            // Check for white space in name for Success/Fail message
            if (firstName.indexOf(' ') >= 0) {
                firstName = name.split(' ').slice(0, -1).join(' ');
                url: rmturl,
                type: "POST",
                data: {
                    name: name,
                    phone: phone,
                    email: email,
                    message: message
                cache: false,
                success: function() {
                    // Success message
                    $('#success').html("<div class='alert alert-success'>");
                    $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
                    $('#success > .alert-success')
                        .append("<strong>Your message has been sent. </strong>");
                    $('#success > .alert-success')

                    //clear all fields
                error: function() {
                    // Fail message
                    $('#success').html("<div class='alert alert-danger'>");
                    $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
                    $('#success > .alert-danger').append("<strong>Sorry " + firstName + ", it seems that my mail server is not responding. Please try again later!");
                    $('#success > .alert-danger').append('</div>');
                    //clear all fields
        filter: function() {
            return $(this).is(":visible");

    $("a[data-toggle=\"tab\"]").click(function(e) {

/*When clicking on Full hide fail/success boxes */
$('#name').focus(function() {

Open in new window

On line 10/11  I define the source file as the variable "rmturl",  In both cases it is simply calling the "contact_me.php" file that simply has one line of code "return true" (I simplified for testing purposes).

When I run to the local file (././mail/contact_me.php), it get the success message to fire (line 37).
But when I run it to the remote server I get the message that says "Sorry, mail server isn't replying". (line 49)

What might be the reason for why this works off the local script but not the remote server? Is there some other parameter that needs to be added to signify this is remote? Or some other protocol?

Paul Konstanski
Project Specialist

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 2 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 2 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004