0

I post my code here.(I add the jquery into my web page)

var dataString ='username='+ username + '&password=' + password; //alert (dataString);return false; $.ajax({ type: "POST", url: "http://hisencha.sinaapp.com/login.php", data: dataString, success: function(data) { if(data=='success'){ window.location.href='list.html'; } else{ alert(data); }; } }); 

above is part of javascript

here is php(demo)

<?php if ($_POST['username']=='aaa' && $_POST['password']=='aaa') { echo 'success'; } else { echo 'error'; } ?> 

What can I do now?And how to fix the error about acrossing domain.

Thank you thank you!

4 Answers 4

1

Yeah, you can use JSONP to do it. Here's some sample jQuery:

 $.ajax({ type: "POST", url: "http://hisencha.sinaapp.com/login.php?callback=?", data: dataString, dataType: 'JSONP', success: function(data) { if(data=='success'){ window.location.href='list.html'; } else{ alert(data); }; } }); 

And PHP:

<?php $response = array( 'something' => 'something' ); echo $_GET[['callback'].'('.json_encode($response).')'; ?> 
Sign up to request clarification or add additional context in comments.

1 Comment

This answer helped me.Thank you very much.It made me know php more!
0

There's no way to use ajax across domains. It's blocked for security reasons.

1 Comment

There are ways if the other domain simply sets a header to allow it...developer.mozilla.org/En/HTTP_access_control
0

you can do it with JSONP. an example

Comments

0

There are many example to do it, with AJAX-CROSS-DOMAIN or Proxy Handle.

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.