Reputation: 1048
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!
Upvotes: 0
Views: 165
Reputation: 2094
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).')';
?>
Upvotes: 1
Reputation: 175
There are many example to do it, with AJAX-CROSS-DOMAIN or Proxy Handle.
Upvotes: 0
Reputation: 3721
There's no way to use ajax across domains. It's blocked for security reasons.
Upvotes: 0