JQuery ajax call returns empty error in Mac Safari and Chrome browsers

I searched for solutions and fixed corrections for several days, but without changes.

The boss man is on a Mac and I don’t have one, so I’ll try to redo the corrections and pass the result to me. So far no luck.

The current setting, so I have a form with usernames and passwords that are submitted after verification. Validation is an ajax call that validates the username and password and then submits the form.

Only on Mac Chrome and Safari (webkit) I get an error from an ajax call that is empty.

I removed the php function that does the check to just respond “hello” so that I know that the problem is not related to php.

So, as soon as the target element is clicked, I will get the username and password values ​​and send an ajax request. (which should hit my php file and just echo hello). However, instead it returns an error without a message. I mean, xhr responseText and thrownError are all just empty / null.

so here is the code: (HTML)

<form id="signin_form" method="POST" action="index.php?cmd=Signin"> <table id="welcomeSignin"> <tr> <td> <div class="welcome"><span class="signin-title-text f-xxlarge-or-link-goth">Welcome Back!</span></div> <div id="error_msg"></div> <table id="input_field_table"> <tr> <td class="input-field-cell"> <div class="singin-titles f-medium-gr-bold">Username</div> </td> <td class="input-field-cell"> <div class="signin-inputs"><input class="signin styled" type="text" name="user_name"></div> </td> </tr> <tr> <td class="input-field-cell"> <div class="singin-titles f-medium-gr-bold">Password</div> </td> <td class="input-field-cell"> <div class="signin-inputs"><input class="signin styled" type="password" name="user_pass"></div> <div class="forgot"><a href="" class="forgot-password f-small-or-link">Forgot your password?</a></div> </td> </tr> <tr> <td colspan="2"> <input type="hidden" name="post_type" value="signin"> <span id="create"><span class="f-medium">Don't have an account? <a href="" class="create"><span class="f-medium-or-link">click here</span></a></span></span> &nbsp; <span class="active-login"><input type="checkbox" class="signin-radio" name="active_login"> <span class="f-medium"> Keep me signed in</span></span> <div id="sign_in"><span class="signin-submit-button"><img src="../images/ready-create-icon.png"></span> <span class="signin-submit-text f-xxxlarge-gr-title-link">Sign In!</span></div> </td> </tr> </table> </td> </tr> </table> 

Nothing special. Here is a jquery snippet:

 $('#sign_in').click(function(){ var url = window.location.href; $('#error_msg').html(''); var username = $('input[name="user_name"]').val(); var password = $('input[name="user_pass"]').val(); var err = ''; $.ajax({ url: ajaxUrl+'validate_signin', type: 'GET', cache: false, data: { username: encodeURIComponent(username), password: encodeURIComponent(password)}, success: function(data, status, xhr){ if(data !== 'OK'){ err = data; $('#error_msg').html(err); return false; }else{ $('#signin_form').submit(); return false; } }, error: function(xhr, ajaxOptions, thrownError){ var tmp_err = ""; tmp_err = ":: "+xhr.responseText+" :: "+xhr.responseXML+" :: "; alert(tmp_err); alert(xhr.responseText); alert(thrownError); window.location.href = url; } }); return false; }); 

The php file is simple: echo "hello"; Exit; just to avoid testing errors.

A few things here, I added encodeURIComponent () because I saw a message describing the problem with special characters and a space. (did not work) for success: I turned on the status and xhr vars just for normal debugging. I just have data.

Now by mistake: this is what appears every time, but all the answers are empty or undefined. I was hoping to get some decent error, but I get nothing. Now it is only on a Mac recently upgraded to Mountian Lion and only on Webkit browsers (Chrome / Safari).

I tried doing only XMLHttpRequest without using jQuery and I get the same.

This works in IE, Firefox, Chrome, and Safari on a PC, and also works on FireFox on its Mac.

Finally, this worked for him earlier, I believe, before updating it.

Any help would be great. I am pulling my hair, I'm more green on jQuery than php, so hopefully one of you can help me.

+7
source share
1 answer

This is a configuration issue. The problem occurred if the domain was entered without a leading www. in the domain name.

Adding a title ('Access-Control-Allow-Origin: *'); The php file resolves this. You can specify specific domains to allow or use *.

+3
source

All Articles