I am trying to connect to a remote server and basically run my application off files on that server. I am able to connect to the server but I don't know how to execute the php files on that server. Here's my javascript function on my local directory which connects to the server:
function test2(){
$.getJSON("http://sampleserver.com/check.php?var=test&callback=?", {
success:function(data){
alert("Working"); },
error: function() {
alert("Error");
}
});
}
This alerts "Working". Here's my check.php on the remote server:
<?php
echo "hello";
echo $_GET['jsoncallback'];
?>
Why is hello not being printed to the screen? How would I actually execute this script once I am connected?
您的脚本已经在执行,但是您正在执行AJAX调用,只是用您自己的消息发出警报,因此您对响应不做任何事情,响应中将包含您好文本。
Here is just one example:
var url = '/m.profile_msg/0/send/';
var dataString = 'msg_body='+ msg_body;
$.ajax({
type: "POST",
url: url,
data: dataString,
success: function(data) {
try {
//var data = jQuery.parseJSON(data);
alert(data);
} catch(e) {
alert(data);
}
}
});
And on the PHP side:
<?php
$xxarray = array('key' => 'value');
echo json_encode($xxarray);
?>
To run remote scripts - try doing your ajax call to a PHP script and have the PHP script shell execute something. But I wouldn't wait for the reply - rather return a status code back to the mobile device saying that the script is running.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.