Get方式传参
Django中的代码如下:
- urls.py代码:
from django.conf.urls import url from django.contrib import admin import AjaxTest.views urlpatterns = [ url(r‘^admin/‘, admin.site.urls), url(r"^index/$",AjaxTest.views.index), ]
- views.py代码:
from django.http import HttpResponse def index(req): print req.GET.get(‘url‘) if req.GET.get(‘url‘)==‘test‘: return HttpResponse("hello,this is a test") else: return HttpResponse("hahahaha")
jQuery中的代码如下:
- 方式1:
$("input").click(function() { $.get("/index/?url=test", function (response, status, xhr) { $(".box").html(response); }); });
- 方式2:
$("input").click(function() { $.get("/index/", "url=test", function (response, status, xhr) { $(".box").html(response); }); });
- 方式3:
$("input").click(function() { $.get("/index/",{ url:"test" },function(response,status,xhr){ $(".box").html(response); }); });
时间: 2024-10-10 08:07:51