-1

I've made a test fiddle here: http://jsfiddle.net/BjLdQ/2

Where I can enter the number 1 for each HTML field and then I press the login button and I get the JSON back as:

{"code":"2"}

So in my mind, I should be able to do the same with jQuery so I press the (Login Jquery Ajax) text and nothing happens, in jsfiddle or from my local machine?

Any help would be most appreciated.

2
  • Did you actually JSLint your code before you submitted this question? Your fiddle has errors. Commented Mar 20, 2012 at 14:29
  • Also, I get this error in the console: XMLHttpRequest cannot load https://api.searchningbo.com/user/login. Origin http://fiddle.jshell.net is not allowed by Access-Control-Allow-Origin. Commented Mar 20, 2012 at 14:31

2 Answers 2

5

Same Origin Policy... You cannot fetch pages from a different origin (MDN).

See Ways to circumvent the same-origin policy for work-arounds.

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

2 Comments

So if i put my javascript on the domain api.searchningbo.com all will be ok? Do I need to have the html, javascript and jquery files all on the same domain?
@Bill The origin is determined by the location of the (HTML) page. Place your html file at hhtps://api.searchningbo.com/ (same PROTOCOL, https and DOMAIN api.searchningbo.com), and the error will disappear.
1

There is an error in the code.

$("#button").click(function() {
     alert("Sending");

      $.ajax({
            type: "POST",
            dataType: 'JSON',
            data: "{'username':'1','password':'1','key':'1','device_Id':'1'}",
            url: "https://api.searchningbo.com/user/login",
            // This was here: },
            success: function(data) {
                alert(data);          

            }

        });
} // It wasnt closed properly   

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.