我从这样的ajax调用php代码:
ajaxRequest.open("GET", "func.php" + queryString, true);
Run Code Online (Sandbox Code Playgroud)
由于这是一个获取请求,任何人都可以通过简单地检查标题来看到它.传递的数据不敏感,但可能会被滥用,因为获取参数名称也很简单.
如何阻止直接访问http://mysite/func.php但允许我的ajax页面访问它?
$request = $event->getRequest();
print_r($request->files);die;
Run Code Online (Sandbox Code Playgroud)
给我
Symfony\Component\HttpFoundation\FileBag Object
(
[parameters:protected] => Array
(
[files] => Array
(
[0] => Symfony\Component\HttpFoundation\File\UploadedFile Object
(
[test:Symfony\Component\HttpFoundation\File\UploadedFile:private] =>
[originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => Chrysanthemum.jpg
[mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => image/jpeg
[size:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 879394
[error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0
[pathName:SplFileInfo:private] => /tmp/phpmUl54W
[fileName:SplFileInfo:private] => phpmUl54W
)
)
)
)
Run Code Online (Sandbox Code Playgroud)
我试图获得'originalname'的值,即"Chrysanthemum.jpg",而不是诉诸循环,但我似乎无法找到正确的语法
使用1UP文件上传器,但我认为这不重要
我遵循以下文档:https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_templates.rst
我选择创建一个子捆绑和覆盖模板,所以在我的捆绑中
class MyBundle extends Bundle
{
//declare bundle as a child of the FOSUserBundle so we can override the parent bundle's templates
public function getParent()
{
return 'FOSUserBundle';
}
}
Run Code Online (Sandbox Code Playgroud)
在我的包中,我添加了以下文件
MyBundle
\Resources
\views
\Security
login.html.twig
Run Code Online (Sandbox Code Playgroud)
匹配文档中提到的FOS捆绑结构
login.html.twig
{% extends 'AnotherBundle::layout.html.twig' %}
{% block title %}Log In{% endblock %}
{% block content %}
{% block fos_user_content %}{% endblock %}
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
当我进入登录页面时,我的标题加载正常,但是没有登录表单,出错了什么?
http://plnkr.co/edit/g89wEeG30sOXhgzHWX0Z?p=preview
我一直在阅读这篇文章,而且似乎共识似乎是在1.1.2*中解决了绑定到原语的问题,但我的问题仍然存在.也许我错误地使用了中继器?请注意,我无法更改数据结构.
我对任何解决方法或创造性黑客都持开放态度.到目前为止,我唯一能够正常工作的是使用这个版本的角度:http: //ci.angularjs.org/job/angular.js-pete/12/artifact/build/angular.js
但我不认为它会很快被修补.思考?
我创建了一个使用async
/ 返回对象的函数await
.我想使函数通用,以便它可以返回我传入的任何对象.除了返回的对象之外,代码是样板文件.我希望能够调用GetAsync并让它返回正确的对象
public Patron getPatronById(string barcode)
{
string uri = "patrons/find?barcode=" + barcode;
Patron Patron = GetAsync(uri).Result;
return Patron;
}
private async Task<Patron> GetAsync(string uri)
{
var client = GetHttpClient(uri);
var content = await client.GetStringAsync(uri);
JavaScriptSerializer ser = new JavaScriptSerializer();
Patron Patron = ser.Deserialize<Patron>(content);
return Patron;
}
Run Code Online (Sandbox Code Playgroud) 我正在使用此代码将表单提交到php脚本:
var valid = 'true';
$(document).ready(function(){
$("#contact").submit(function(){
$.post("process.php",
$("#contact").serialize(),
function(data){
if(data.email_check == 'invalid'){
valid = 'false'; //<---not set!
$("#email1").addClass('missing');
$("#message_ajax")
.html("<div class='errorMessage'>Sorry is NOT a valid e-mail address. Try again.</div>");
} else {
$("#message_ajax")
.html("<div class='errorMessage'>YES! this is A valid e-mail address. DO NOT Try again.</div>");
}
}, "json"
);
if(valid == 'true'){
$("#contact").hide();
}
return false;
});
});
Run Code Online (Sandbox Code Playgroud)
我知道脚本返回'invalid'值,因为div和css按预期更新,但'valid'变量永远不会设置为'false'.认为这是一个范围问题我已经移动了声明,如果声明周围没有喜悦.
可能的相关问题 - 我正在使用firebug来逐步执行代码,但它只在第一次执行代码时在断点处停止,而且从不再次,但我可以提交表单任意次,它总是按预期响应 - 有效或无效.如你所见,我对jQuery很新.
我需要使用1.3.2库,遗憾的是它不支持最后的功能.这导致我的功能失败:
$op.last().next().after($op);
Run Code Online (Sandbox Code Playgroud)
"$ op.last不是函数"
演示:
我在纯js中重写这个功能是不成功的,有什么建议吗?注意,我还需要.first(),但我假设我能够从.last备用代码中推断出它.非常感谢-
php脚本返回一个值,第一个警报正常工作.
我无法在第二个警报中引用httprequest返回的值.理想情况下,我会调用函数get_captcha() - 它会返回值 - 它只是我不知道如何做到这一点.
我意识到在全球范围内设置变量可能不是最好的方法,但这是我唯一能想到的 - 我对替代方案持开放态度.
<script type="text/javascript">
var url = "captcha_get_code.php"; // The server-side script
var cap;
function ValidateForm() {
get_captcha()
alert(cap); //undefined
}
function get_captcha() {
http.open("GET", url, true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
function handleHttpResponse() {
if (http.readyState == 4) {
if (http.status==200) {
//return http.responseText;
cap=http.responseText;
alert(cap); //this one works
}
}
}
function getHTTPObject() {
var xmlhttp;
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject){
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
if (!xmlhttp){
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); …
Run Code Online (Sandbox Code Playgroud)