0

Hi I have a code for posting on my site and it works perfectly in safari, but in firefox not. I don't know the problem, because the code is very simple ... Here the code:

<input type="text" placeholder="mmm..." class="bar" name="txt" /> <input type="hidden" value="" name="map" /> <button onclick="post('2')">send</button> <div id="prueba"></div> <script src="http://code.jquery.com/jquery-latest.js"></script> <script> function post(id) { var txtvalue = document.getElementsByName('txt')[0].value; if (document.getElementsByName('map')[0]) { var mapv = document.getElementsByName('map')[0].value; } else { var mapv = ""; } $('#prueba').html('txt:' + txtvalue + '<br>map:' + mapv); $.ajax({ type: "POST", url: "http://m2s.es/app/api/connect/chat.php", data: { txt: txtvalue, map: mapv, id: id }, dataType: 'text', beforeSend: function() { console.log('connecting...') }, complete: function() { console.log('procesing...') }, success: function(result) { console.log(result); }, error: function(XMLHttpRequest, textStatus, errorThrown) { console.error(textStatus); } }) } </script> 

For that the PHP process the post, you must be logged in to the http://m2s.es/app, but still in firefox will give error in the console (with login or not) and not as in safari, if you don't login, it will say in the console: 'not Login'

1
  • 1
    What is the error message in the console that Firefox gives? Commented Jan 23, 2014 at 16:29

3 Answers 3

1

this may caused by crossdomain, if you didn't run this js code under http://m2s.es/ , it will cause the crossdomain problem, and you will get error in ajax.

Sign up to request clarification or add additional context in comments.

5 Comments

this seems like wild speculation to me.
And, why in Safari works fine? Is there any way to make it work without being in the domain?
@user3228573 this may different from browser to browser. jsonp is a way to solve the crossdomain problem
Has you got other solution?
If it is cross domain, there is CORS.
1

Well the one issue I see is not related to the bug is

if (document.getElementsByName('map')[0]) { 

if the length is zero, than you will have an error

var map = document.getElementsByName('map'); var mapv = map.length ? map[0].value : ""; 

or just use jQuery

var mapv = $('[name="map"]').val(); 

Comments

1

When I logged on to your site I got the following in firefox, using firebug:

TypeError: input is null : appnew.js (line 40)

39 var input = document.getElementById('input'); 40 input.onkeyup = function () { 

On line 39 you are trying to get an element with id=input, but since you dont have any element with id input line 40 gives the error.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.