开发者

Can I pass my form values through jQuery .load() and make them readable by PHP $_POST?

开发者 https://www.devze.com 2023-03-12 22:31 出处:网络
Can I pass form values in load() function开发者_StackOverflow of jQuery then be able to read them as $_POST parameters in php? ...Sure, add an object with the values as 2nd parameter to your load call

Can I pass form values in load() function开发者_StackOverflow of jQuery then be able to read them as $_POST parameters in php? ...


Sure, add an object with the values as 2nd parameter to your load call. See the docs where is stated:

The POST method is used if data is provided as an object; otherwise, GET is assumed.

So your JavaScript could look like:

$('#result').load('ajax/call.php', { postVarName: 'value' }, function() {
  alert('Load was performed.');
});

In PHP you can now access it:

echo $_POST["postVarName"]; // will echo: value
0

精彩评论

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