请帮助我,如果有人能给我一个例子如何使用ajax与cakephp 2.3.0一个例子是这样的
<?php echo $this->html->link('Original', '#',
array('onclick'=>'return false;', 'id'=>'remanufactured-link', 'class'=>'get-type-product-link')); ?>
<div id="content">
</div>
Run Code Online (Sandbox Code Playgroud)
当我点击original链接时,带有id的div content会发生变化.我怎么能用cakephp 2.3.0做到这一点?
我已经制作了一个将发送输入类型文件的表单,在我的服务器端我希望获得$_FILES值,所以我使用print_r($_FILES),但在我的ajax响应我没有得到任何价值,这里我的代码..
<form id="my_form">
<input type="file" id="image_file" name="image_file"/>
</form>
$('#my_form').submit(function() {
var data = $('#my_form').serialize();
$.ajax({
url: 'ajax.php',
type: 'POST',
data: data,
enctype: 'multipart/form-data',
success: function(response) {
alert(response);
},
});
return false;
});
Run Code Online (Sandbox Code Playgroud)
在这里我的PHP代码
<?php
$name = $_FILES['image_file']['name']; // get the name of the file
$type = $_FILES['image_file']['type']; // get the type of the file
$size = $_FILES['image_file']['size'];
echo $name;
//or
print_r($_FILES);
?>
Run Code Online (Sandbox Code Playgroud)
请帮我 ...
谢谢..
当我使用 PHP 在 XML 中添加新元素时,如何设置属性。我的PHP代码是这样的:
<?php
$xml = simplexml_load_file ( 'log.xml' );
$movies = $xml->addChild("time");
// add attribut `value` here in tag time
$user = $movies->addChild("user", "");
// add attribut `id` here in tag user
$action = $user->addChild("action","");
// add attribut `value` here in tag action
$action->addChild("table","customers");
$action->addChild("table_id","1");
echo $xml->saveXML( 'log.xml' );
?>
Run Code Online (Sandbox Code Playgroud)
我希望输出看起来像这样:
// log.xml
<?xml version="1.0" encoding="utf-8"?>
<log>
<time value="2013-01-10 12:20:01">
<user id="1">
<action value="delete">
<table>customer</table>
<table_id>1</table_id>
</action>
<action value="insert">
<table>customer</table>
<data>
<nama>budi</nama>
</data>
</action>
<action value="update">
<table>customer</table> …Run Code Online (Sandbox Code Playgroud) 我做了一个函数将返回序列号的第N位,例如:
1234567891011121314151617
我的功能是这样的
<?php
function getLength($number) {
$length = 0;
if ($number == 0){
$length = 1;
} else {
$length = (int) log10($number)+1;
}
return $length;
}
?>
<?php
function getDigitNumber($digit){
$number = 10000000000;
$data = array();
for($i=1;$i<=$number;$i++){
if(getLength($i) > 1){
$array = str_split($i,1);
for($n=0;$n<=count($array)-1;$n++){
array_push($data,$array[$n]);
}
}else{
$data[$i] = $i;
}
}
return $data[$digit];
}
?>
Run Code Online (Sandbox Code Playgroud)
当我执行我有一个像这个错误消息的问题"致命错误:允许的内存大小134217728字节耗尽(试图分配36个字节)".也许是因为我在var中分配了一个大数字$number
我该如何解决..或者我如何能够处理这些大数字的功能
谢谢..