1

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);

 }
10
  • 1
    What do you mean by load? What's wrong with AJAX? Commented Aug 14, 2011 at 15:18
  • 1
    What do you understand by load a URL? What do you expect to happen? What do you want to do? Commented Aug 14, 2011 at 15:19
  • @Felix Kling url of php script Commented Aug 14, 2011 at 15:51
  • @amiawizard: That does not all answer my questions and I already understood that. If you provide more information you will get better answers. Commented Aug 14, 2011 at 16:09
  • 2
    You execute a PHP script by requesting from a server to run the resource. Do you mean how do you trigger a form submission in the browser that points to your PHP page? Commented Aug 14, 2011 at 16:15

3 Answers 3

3

simple

jQuery and:

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

Later edit:

for form use serialize:

<script>
    $.post("myPHP.php", $("#myFormID").serialize());
</script>
Sign up to request clarification or add additional context in comments.

4 Comments

Are you sure that executes it? for me it's just sending a get request to the url.
as soon as the url is hit the code inside that url executes as PHP stands for Preprocesing HyperText ...
In the script I execute there is a view that is suppose to be loaded, why isn't it loading?
Sending a get request to a url causes the scripts in the url to execute.
1

like this ?

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

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.