开发者

How to send data to a php script page during jQuery load and accept the data

开发者 https://www.devze.com 2023-03-23 15:27 出处:网络
I have a php function that builds a list of items for me. Im not sure but i read that you cant call a php function explicitly though jQuery/js.

I have a php function that builds a list of items for me. Im not sure but i read that you cant call a php function explicitly though jQuery/js.

So i saw that you can still call php pages like this:

$("#name").click(function(){  
  $("#div").load("script.php");  
}); 

If i can call a php page like that, is there also a way to send it a URL when that page is loaded like this?

$("#name").click(function(){  
  $("#div").load("script.php", 'http://gdata.youtube.com/feeds/');  
}); 

also another problem comes up that how do i make the script accept that string through from jQuery?

normally when you call a function you pass parameter with the call like so:

<?php makeList( 'http://gdata.开发者_JAVA技巧youtube.com/feeds/' ); ?>

//on the function-side
<?php 
function makeList( $feedURL ) 
{
//...stuff that uses $feedURL...
}
?>

Since i will make the function a script that runs upon being called how would i pass it a parameter?

I have no idea if this is possible or not and i would understand if this creates tons of security issues which makes it not acceptable.


You have the $.get and $.post methods in jQuery.

$.post('script.php', { url: 'http://gdata.youtube.com/feeds/' }, function(data) {
    //data will hold the output of your script.php
});

The url is posted to your PHP script and you can access it through $_POST['url'].


See jQuery.ajax(), the 'sending data to the server' example.

0

精彩评论

暂无评论...
验证码 换一张
取 消