简体   繁体   English

如何通过jquery ajax调用在php页面上获取价值

[英]How to get value on php page by jquery ajax call

I am using the jquery ajax script for getting the content of php page without loading of page. 我正在使用jquery ajax脚本来获取php页面的内容而不加载页面。 Using following script 使用以下脚本

$('#data_subpartition_result').live('click', function(){
    $.ajax({
           type: "POST",
           url: "temp/model_view_result.php",
           context: "language=php&version=5",
           data: {train: 0.7, validation: 0.2, test: 0.1},
           success: function(result){
                    $('div.divRightModelContent').html(result);
               }
    });
});

and my php file code is as follows 和我的PHP文件代码如下

<?php 
     echo $_POST['train'];

     // some other php stuff

?>

i am trying to print or using value of data which i have passed with post method by jquery ajax call but i have an error and no any value passed in post method on php page by jquery ajax call. 我正在尝试打印或使用通过jquery ajax调用通过post方法传递的数据值,但我有一个错误,并且没有通过jquery ajax调用在php页面上的post方法传递任何值。 Give me any idea how to get the value. 让我知道如何获得价值。

It's been years since I programmed in PHP, but here are a few jQuery things to correct. 自从我用PHP编程以来已经有好几年了,但是这里有一些要纠正的jQuery问题。

  1. context is not used the way you're using it. context未按您使用的方式使用。 It's used to tell the $.ajax call to load a particular section of the url property. 它用于告诉$.ajax调用加载url属性的特定部分。
  2. Because you specified type: "POST" , your .html() call should be: ('div.divRightModelContent').html(result.d) . 因为您指定了type: "POST" ,所以您的.html()调用应该是:( ('div.divRightModelContent').html(result.d)

There are some good examples on the official jQuery.ajax() webpage. 官方jQuery.ajax()网站上有一些很好的示例。 They're pretty good about at least providing you with example data under each property. 它们至少在每个属性下为您提供示例数据非常不错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM