开发者

Execute php url with JS

Is it possibe to simply load a php script with a url with js?

$(function() {

            $('form').submit(function(e) {

                e.preventDefault();

                var title = $('#title:input').val();
                var urlsStr = $("#links").val();
                var urls = urlsStr.match(/\bhttps?:\/\/[^\s]+/gi);
                var formData = {
                    "title": title,
                    "urls": urls
                }
                var jsonForm = JSON.stringify(formData);                

                $.ajax({
                    type: 'GET',
                    cache: false,
                    data: { jsonForm : jsonForm },
                    url: 'publishlinks/publish'      开发者_开发问答              
                 })

                 //load php script

            });

});

Edit:

 function index() {

            $this->load->model('NewsFeed_model');
            $data['queryMovies'] = $this->NewsFeed_model->getPublications();        
            $this->load->view('news_feed_view', $data);

 }


simple

jQuery and:

<script>
    $.get('myPHP.php', function(data) {});
</script>

Later edit:

for form use serialize:

<script>
    $.post("myPHP.php", $("#myFormID").serialize());
</script>


like this ?

$.get('myPHP.php', function(data) {
  $('.result').html(data);
  alert('Load was performed.');
});


There are various ways to execute a server side page using jQuery. Every method has its own configuration and at the minimum you have to specify the url which you want to request.

$.ajax

$.ajax({
     type: "Get",//Since you just have to request the page
     url:"test.php",
     data: {},//In case you want to provide the data along with the request
     success: function(data){},//If you want to do something after the request is successfull
     failure: function(){}, //If you want to do something if the request fails
   });

$.get

 $.get("test.php");//Simplest one if you just dont care whether the call went through or not

$.post

var data = {};
$.post("test.php", data, function(data){});

You can get the form data as a json object as below

var data = $("formSelector").searialize();//This you can pass along with your request
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜