1

I want to commit the string "123456" to the aaa.php script with the jQuery load() function. The general syntax of the load() function looks like this:

$(selector).load(url,data,function(response,status,xhr))

In my case I use the function in the following way

$("#htmlElement").load("scripts/aaa.php",'123456');

How can I get access to the string "123456" inside the following php script?

<?php
  $input; //this should be the string "123456"
  //some calculations
  echo result;

3 Answers 3

1

In order to use .load() to send data you would have to enclose the data properly:

 $("#htmlElement").load("scripts/aaa.php",{data:'123456'});

Once done the value will be available in the POST array:

$input = $_POST['data']; // will be 123456
Sign up to request clarification or add additional context in comments.

Comments

1

In Js:

$("#htmlElement").load("scripts/aaa.php",{data:'123456'});

In php you can access a post string like below:

$input = $_POST['data'];

Comments

0

You can assign '123456' to an element, and then call it back in the php e.g.

$( "#new-projects" ).load( "/resources/load.html #projects li" );

Have a read of this, it explained the load function perfectly allowing you to find your answer - http://api.jquery.com/load/

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.